Skip to content

Commit

Permalink
feat(wip): more immutable dynamic enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
sdd committed Nov 16, 2024
1 parent 7e50b84 commit 5424739
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 98 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ csv = "1"
cmov = "0.3.1"
rstest = "0.23.0"
array-init = "2.1.0"
aligned-vec = "0.6.1"

[dev-dependencies]
bincode = "1.3"
Expand Down
6 changes: 2 additions & 4 deletions examples/pointcloud-csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::io::Write;
use std::time::Instant;

use csv::Reader;
use kiddo::ImmutableKdTree;
use kiddo::ImmutableKdDynamicTree;
use kiddo::SquaredEuclidean;
use rkyv::ser::serializers::{AlignedSerializer, BufferScratch, CompositeSerializer};
use rkyv::ser::Serializer;
Expand All @@ -30,7 +30,7 @@ struct Point {
z: f64,
}

type Tree = ImmutableKdTree<f64, 3>;
type Tree = ImmutableKdDynamicTree<f64, 3>;

fn main() -> Result<(), Box<dyn Error>> {
#[cfg(feature = "tracing")]
Expand Down Expand Up @@ -61,8 +61,6 @@ fn main() -> Result<(), Box<dyn Error>> {
ElapsedDuration::new(start.elapsed())
);

println!("Tree Stats: {:?}", kdtree.generate_stats());

// Test query on the newly created tree
let query = [0.123f64, 0.456f64, 0.789f64];
let nearest_neighbour = kdtree.nearest_one::<SquaredEuclidean>(&query);
Expand Down
6 changes: 2 additions & 4 deletions examples/pointcloud-las.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::fs::File;
use std::io::Write;
use std::time::Instant;

use kiddo::ImmutableKdTree;
use kiddo::ImmutableKdDynamicTree;
use kiddo::SquaredEuclidean;
use las::Reader;

Expand All @@ -22,7 +22,7 @@ use tracing_subscriber::fmt;
const BUFFER_LEN: usize = 10_000_000_000;
const SCRATCH_LEN: usize = 1_000_000_000;

type Tree = ImmutableKdTree<f32, 3>;
type Tree = ImmutableKdDynamicTree<f32, 3>;

fn main() -> Result<(), Box<dyn Error>> {
#[cfg(feature = "tracing")]
Expand Down Expand Up @@ -53,8 +53,6 @@ fn main() -> Result<(), Box<dyn Error>> {
ElapsedDuration::new(start.elapsed())
);

println!("Tree Stats: {:?}", kdtree.generate_stats());

// Test query on the newly created tree
let query = [0.123f32, 0.456f32, 0.789f32];
let nearest_neighbour = kdtree.nearest_one::<SquaredEuclidean>(&query);
Expand Down
1 change: 1 addition & 0 deletions src/float_leaf_slice/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use az::Cast;

use crate::{float::kdtree::Axis, types::Content};

#[inline]
pub(crate) fn get_best_from_dists_autovec<A: Axis, T: Content>(
acc: &[A],
items: &[T],
Expand Down
16 changes: 14 additions & 2 deletions src/float_leaf_slice/leaf_slice.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use az::Cast;
use std::slice::ChunksExact;

const CHUNK_SIZE: usize = 32;

#[cfg(all(
feature = "simd",
target_feature = "avx2",
Expand Down Expand Up @@ -34,6 +36,7 @@ where
T: Content,
usize: Cast<T>,
{
#[inline]
pub fn nearest_one<D>(&self, query: &[A; K], best_dist: &mut A, best_item: &mut T)
where
D: DistanceMetric<A, K>,
Expand Down Expand Up @@ -77,6 +80,7 @@ impl<'a, A: Axis, T: Content, const K: usize, const C: usize> Iterator
{
type Item = ([&'a [A; C]; K], &'a [T; C]);

#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.items_iterator.is_empty() {
None
Expand All @@ -93,6 +97,7 @@ impl<'a, A: Axis, T: Content, const K: usize, const C: usize> Iterator
impl<'a, A: Axis, T: Content, const K: usize, const C: usize>
LeafFixedSliceIterator<'a, A, T, K, C>
{
#[inline]
fn remainder(&self) -> ([&'a [A]; K], &'a [T]) {
(
array_init::array_init(|i| self.points_iterators[i].remainder()),
Expand Down Expand Up @@ -122,6 +127,7 @@ where
T: Content,
usize: Cast<T>,
{
#[inline]
pub fn new<'a>(content_points: [&'a [A]; K], content_items: &'a [T]) -> LeafSlice<'a, A, T, K> {
let size = content_items.len();
for arr in content_points {
Expand All @@ -134,6 +140,7 @@ where
}
}

#[inline]
fn as_full_chunks<const C: usize>(&self) -> LeafFixedSliceIterator<A, T, K, C> {
let points_iterators = self.content_points.map(|i| i.chunks_exact(C));
let items_iterator = self.content_items.chunks_exact(C);
Expand All @@ -144,14 +151,15 @@ where
}
}

#[inline]
pub fn nearest_one<D>(&self, query: &[A; K], best_dist: &mut A, best_item: &mut T)
where
D: DistanceMetric<A, K>,
{
let chunk_iter = self.as_full_chunks::<64>();
let chunk_iter = self.as_full_chunks::<CHUNK_SIZE>();
let (remainder_points, remainder_items) = chunk_iter.remainder();
for chunk in chunk_iter {
let dists = A::dists_for_chunk::<D, 64>(chunk.0, query);
let dists = A::dists_for_chunk::<D, CHUNK_SIZE>(chunk.0, query);
A::update_best_dist(dists, chunk.1, best_dist, best_item);
}

Expand Down Expand Up @@ -180,6 +188,7 @@ where
T: Content,
usize: Cast<T>,
{
#[inline]
fn update_best_dist<const C: usize>(
acc: [f64; C],
items: &[T; C],
Expand Down Expand Up @@ -213,6 +222,7 @@ where
}
}

#[inline]
fn dists_for_chunk<D, const C: usize>(chunk: [&[Self; C]; K], query: &[Self; K]) -> [Self; C]
where
D: DistanceMetric<Self, K>,
Expand All @@ -237,6 +247,7 @@ where
T: Content,
usize: Cast<T>,
{
#[inline]
fn update_best_dist<const C: usize>(
acc: [f32; C],
items: &[T; C],
Expand Down Expand Up @@ -268,6 +279,7 @@ where
}
}

#[inline]
fn dists_for_chunk<D, const C: usize>(chunk: [&[Self; C]; K], query: &[Self; K]) -> [Self; C]
where
D: DistanceMetric<Self, K>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ macro_rules! generate_immutable_dynamic_approx_nearest_one {
let mut level: usize = 0;
let mut leaf_idx: usize = 0;

while level <= self.max_stem_level {
while level <= self.max_stem_level as usize {
let val = *unsafe { self.stems.get_unchecked(curr_idx) };

Check failure on line 24 in src/immutable_dynamic/common/generate_immutable_dynamic_approx_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (nightly)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_approx_nearest_one.rs:24:41 | 24 | let val = *unsafe { self.stems.get_unchecked(curr_idx) }; | ^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/approx_nearest_one.rs:59:5 | 59 | / generate_immutable_dynamic_approx_float_nearest_one!( 60 | | "use std::fs::File; 61 | | use memmap::MmapOptions; ... | 64 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 65 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others = note: this error originates in the macro `generate_immutable_dynamic_approx_nearest_one` which comes from the expansion of the macro `generate_immutable_dynamic_approx_float_nearest_one` (in Nightly builds, run with -Z macro-backtrace for more info)

Check failure on line 24 in src/immutable_dynamic/common/generate_immutable_dynamic_approx_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Run Tests (Nightly, all features enabled)

the trait bound `AVec<A, ConstAlign<128>>: Archive` is not satisfied

Check failure on line 24 in src/immutable_dynamic/common/generate_immutable_dynamic_approx_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Test Coverage

the trait bound `AVec<A, ConstAlign<128>>: Archive` is not satisfied

Check failure on line 24 in src/immutable_dynamic/common/generate_immutable_dynamic_approx_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_approx_nearest_one.rs:24:41 | 24 | let val = *unsafe { self.stems.get_unchecked(curr_idx) }; | ^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/approx_nearest_one.rs:59:5 | 59 | / generate_immutable_dynamic_approx_float_nearest_one!( 60 | | "use std::fs::File; 61 | | use memmap::MmapOptions; ... | 64 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 65 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others = note: this error originates in the macro `generate_immutable_dynamic_approx_nearest_one` which comes from the expansion of the macro `generate_immutable_dynamic_approx_float_nearest_one` (in Nightly builds, run with -Z macro-backtrace for more info)
let is_right_child = *unsafe { query.get_unchecked(dim) } >= val;

Expand All @@ -32,13 +32,13 @@ macro_rules! generate_immutable_dynamic_approx_nearest_one {
dim = (dim + 1) % K;
}

let leaf_extent: core::range::Range<usize> = unsafe { *self.leaf_extents.get_unchecked(leaf_idx) };
let (start, end) = unsafe { *self.leaf_extents.get_unchecked(leaf_idx) };

let leaf_slice = $crate::float_leaf_slice::leaf_slice::LeafSlice::new(
array_init::array_init(|i|
&self.leaf_points[i][leaf_extent]
&self.leaf_points[i][start as usize..end as usize]
),
&self.leaf_items[leaf_extent],
&self.leaf_items[start as usize..end as usize],
);

leaf_slice.nearest_one::<D>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ macro_rules! generate_immutable_dynamic_nearest_one {
D: DistanceMetric<A, K>,
{
let mut off = [A::zero(); K];
let mut result = NearestNeighbour {
distance: A::max_value(),
item: T::zero(),
};

self.nearest_one_recurse::<D>(

Check failure on line 18 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (nightly)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:18:22 | 18 | self.nearest_one_recurse::<D>( | ^^^^^^^^^^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others note: required by a bound in `immutable_dynamic::float::kdtree::ArchivedImmutableDynamicKdTree` --> src/immutable_dynamic/float/kdtree.rs:45:12 | 45 | derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) | ^^^^^^^^^^^^^ required by this bound in `ArchivedImmutableDynamicKdTree` ... 48 | pub struct ImmutableDynamicKdTree< | ---------------------- required by a bound in this struct = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the derive macro `rkyv::Archive` (in Nightly builds, run with -Z macro-backtrace for more info)

Check failure on line 18 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:18:22 | 18 | self.nearest_one_recurse::<D>( | ^^^^^^^^^^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others note: required by a bound in `immutable_dynamic::float::kdtree::ArchivedImmutableDynamicKdTree` --> src/immutable_dynamic/float/kdtree.rs:45:12 | 45 | derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) | ^^^^^^^^^^^^^ required by this bound in `ArchivedImmutableDynamicKdTree` ... 48 | pub struct ImmutableDynamicKdTree< | ---------------------- required by a bound in this struct = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the derive macro `rkyv::Archive` (in Nightly builds, run with -Z macro-backtrace for more info)
query,
0,
0,
NearestNeighbour {
distance: A::max_value(),
item: T::zero(),
},
&mut result,
&mut off,
A::zero(),
0,
// 0,
0,
)
);

result
}

#[allow(clippy::too_many_arguments)]
Expand All @@ -31,21 +36,22 @@ macro_rules! generate_immutable_dynamic_nearest_one {
query: &[A; K],
stem_idx: usize,
split_dim: usize,
mut nearest: NearestNeighbour<A, T>,
nearest: &mut NearestNeighbour<A, T>,
off: &mut [A; K],
rd: A,
mut level: usize,
// mut minor_level: u64,
mut leaf_idx: usize,
) -> NearestNeighbour<A, T>
)
where
D: DistanceMetric<A, K>,
{
// use cmov::Cmov;
use $crate::modified_van_emde_boas::modified_van_emde_boas_get_child_idx_v2_branchless;

if level > self.max_stem_level {
self.search_leaf_for_nearest::<D>(query, &mut nearest, leaf_idx as usize);
return nearest;
if level > self.max_stem_level as usize {
self.search_leaf_for_nearest::<D>(query, nearest, leaf_idx as usize);

Check failure on line 53 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (nightly)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:53:26 | 53 | self.search_leaf_for_nearest::<D>(query, nearest, leaf_idx as usize); | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others note: required by a bound in `immutable_dynamic::float::kdtree::ArchivedImmutableDynamicKdTree` --> src/immutable_dynamic/float/kdtree.rs:45:12 | 45 | derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) | ^^^^^^^^^^^^^ required by this bound in `ArchivedImmutableDynamicKdTree` ... 48 | pub struct ImmutableDynamicKdTree< | ---------------------- required by a bound in this struct = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the derive macro `rkyv::Archive` (in Nightly builds, run with -Z macro-backtrace for more info)

Check failure on line 53 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:53:26 | 53 | self.search_leaf_for_nearest::<D>(query, nearest, leaf_idx as usize); | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others note: required by a bound in `immutable_dynamic::float::kdtree::ArchivedImmutableDynamicKdTree` --> src/immutable_dynamic/float/kdtree.rs:45:12 | 45 | derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) | ^^^^^^^^^^^^^ required by this bound in `ArchivedImmutableDynamicKdTree` ... 48 | pub struct ImmutableDynamicKdTree< | ---------------------- required by a bound in this struct = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the derive macro `rkyv::Archive` (in Nightly builds, run with -Z macro-backtrace for more info)
return;
}

let val = *unsafe { self.stems.get_unchecked(stem_idx as usize) };

Check failure on line 57 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (nightly)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:57:37 | 57 | let val = *unsafe { self.stems.get_unchecked(stem_idx as usize) }; | ^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the macro `generate_immutable_dynamic_float_nearest_one` (in Nightly builds, run with -Z macro-backtrace for more info)

Check failure on line 57 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:57:37 | 57 | let val = *unsafe { self.stems.get_unchecked(stem_idx as usize) }; | ^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the macro `generate_immutable_dynamic_float_nearest_one` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand All @@ -55,85 +61,76 @@ macro_rules! generate_immutable_dynamic_nearest_one {
let closer_leaf_idx = leaf_idx + is_right_child;
let farther_leaf_idx = leaf_idx + (1 - is_right_child);

let closer_node_idx = modified_van_emde_boas_get_child_idx_v2_branchless(stem_idx, is_right_child == 1, level);
let further_node_idx = modified_van_emde_boas_get_child_idx_v2_branchless(stem_idx, is_right_child == 0, level);
let closer_node_idx = modified_van_emde_boas_get_child_idx_v2_branchless(stem_idx, is_right_child == 1, /*minor_*/level);
let further_node_idx = modified_van_emde_boas_get_child_idx_v2_branchless(stem_idx, is_right_child == 0, /*minor_*/level);

let mut rd = rd;
let old_off = off[split_dim];
let new_off = query[split_dim].saturating_dist(val);

level += 1;
let next_split_dim = (split_dim + 1).rem(K);
// minor_level += 1;
// minor_level.cmovnz(&0, u8::from(minor_level == 3));

let nearest_neighbour = self.nearest_one_recurse::<D>(
self.nearest_one_recurse::<D>(

Check failure on line 76 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (nightly)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:76:22 | 76 | self.nearest_one_recurse::<D>( | ^^^^^^^^^^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others note: required by a bound in `immutable_dynamic::float::kdtree::ArchivedImmutableDynamicKdTree` --> src/immutable_dynamic/float/kdtree.rs:45:12 | 45 | derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) | ^^^^^^^^^^^^^ required by this bound in `ArchivedImmutableDynamicKdTree` ... 48 | pub struct ImmutableDynamicKdTree< | ---------------------- required by a bound in this struct = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the derive macro `rkyv::Archive` (in Nightly builds, run with -Z macro-backtrace for more info)

Check failure on line 76 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:76:22 | 76 | self.nearest_one_recurse::<D>( | ^^^^^^^^^^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others note: required by a bound in `immutable_dynamic::float::kdtree::ArchivedImmutableDynamicKdTree` --> src/immutable_dynamic/float/kdtree.rs:45:12 | 45 | derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) | ^^^^^^^^^^^^^ required by this bound in `ArchivedImmutableDynamicKdTree` ... 48 | pub struct ImmutableDynamicKdTree< | ---------------------- required by a bound in this struct = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the derive macro `rkyv::Archive` (in Nightly builds, run with -Z macro-backtrace for more info)
query,
closer_node_idx,
next_split_dim,
nearest,
off,
rd,
level,
// minor_level,
closer_leaf_idx,
);

if nearest_neighbour < nearest {
nearest = nearest_neighbour;
}

rd = Axis::rd_update(rd, D::dist1(new_off, old_off));

if rd <= nearest.distance {
off[split_dim] = new_off;

let result = self.nearest_one_recurse::<D>(
self.nearest_one_recurse::<D>(

Check failure on line 92 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (nightly)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:92:26 | 92 | self.nearest_one_recurse::<D>( | ^^^^^^^^^^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others note: required by a bound in `immutable_dynamic::float::kdtree::ArchivedImmutableDynamicKdTree` --> src/immutable_dynamic/float/kdtree.rs:45:12 | 45 | derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) | ^^^^^^^^^^^^^ required by this bound in `ArchivedImmutableDynamicKdTree` ... 48 | pub struct ImmutableDynamicKdTree< | ---------------------- required by a bound in this struct = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the derive macro `rkyv::Archive` (in Nightly builds, run with -Z macro-backtrace for more info)

Check failure on line 92 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:92:26 | 92 | self.nearest_one_recurse::<D>( | ^^^^^^^^^^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others note: required by a bound in `immutable_dynamic::float::kdtree::ArchivedImmutableDynamicKdTree` --> src/immutable_dynamic/float/kdtree.rs:45:12 | 45 | derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) | ^^^^^^^^^^^^^ required by this bound in `ArchivedImmutableDynamicKdTree` ... 48 | pub struct ImmutableDynamicKdTree< | ---------------------- required by a bound in this struct = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the derive macro `rkyv::Archive` (in Nightly builds, run with -Z macro-backtrace for more info)
query,
further_node_idx,
next_split_dim,
nearest,
off,
rd,
level,
// minor_level,
farther_leaf_idx,
);
off[split_dim] = old_off;

if result < nearest {
nearest = result;
}
}

nearest
}

#[inline]
fn search_leaf_for_nearest<D>(
fn search_leaf_for_nearest<D>(
&self,

Check failure on line 109 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (nightly)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:109:18 | 109 | &self, | ^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others note: required by a bound in `immutable_dynamic::float::kdtree::ArchivedImmutableDynamicKdTree` --> src/immutable_dynamic/float/kdtree.rs:45:12 | 45 | derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) | ^^^^^^^^^^^^^ required by this bound in `ArchivedImmutableDynamicKdTree` ... 48 | pub struct ImmutableDynamicKdTree< | ---------------------- required by a bound in this struct = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the derive macro `rkyv::Archive` (in Nightly builds, run with -Z macro-backtrace for more info)

Check failure on line 109 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Run Tests (Nightly, all features enabled)

the trait bound `AVec<A, ConstAlign<128>>: Archive` is not satisfied

Check failure on line 109 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Test Coverage

the trait bound `AVec<A, ConstAlign<128>>: Archive` is not satisfied

Check failure on line 109 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Cargo Check (Nightly)

the trait bound `AVec<A, ConstAlign<128>>: Archive` is not satisfied

Check failure on line 109 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:109:18 | 109 | &self, | ^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others note: required by a bound in `immutable_dynamic::float::kdtree::ArchivedImmutableDynamicKdTree` --> src/immutable_dynamic/float/kdtree.rs:45:12 | 45 | derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) | ^^^^^^^^^^^^^ required by this bound in `ArchivedImmutableDynamicKdTree` ... 48 | pub struct ImmutableDynamicKdTree< | ---------------------- required by a bound in this struct = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the derive macro `rkyv::Archive` (in Nightly builds, run with -Z macro-backtrace for more info)
query: &[A; K],
nearest: &mut NearestNeighbour<A, T>,
leaf_idx: usize,
) where
D: DistanceMetric<A, K>,
{
let leaf_extent = unsafe { self.leaf_extents.get_unchecked(leaf_idx) };
// let leaf_extent = self.leaf_extents[leaf_idx];
let (start, end) = unsafe { *self.leaf_extents.get_unchecked(leaf_idx) };

// Artificially extend size to be at least chunk length for faster processing
// TODO: why does this slow things down?
// let end = end.max(start + 32).min(self.leaf_items.len() as u32);

let leaf_slice = $crate::float_leaf_slice::leaf_slice::LeafSlice::new(
array_init::array_init(|i|

Check failure on line 123 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (nightly)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:123:21 | 123 | array_init::array_init(|i| | ^^^^^^^^^^^^^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others note: required by a bound in `immutable_dynamic::float::kdtree::ArchivedImmutableDynamicKdTree` --> src/immutable_dynamic/float/kdtree.rs:45:12 | 45 | derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) | ^^^^^^^^^^^^^ required by this bound in `ArchivedImmutableDynamicKdTree` ... 48 | pub struct ImmutableDynamicKdTree< | ---------------------- required by a bound in this struct = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the derive macro `rkyv::Archive` (in Nightly builds, run with -Z macro-backtrace for more info)

Check failure on line 123 in src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied

error[E0277]: the trait bound `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>: rkyv::Archive` is not satisfied --> src/immutable_dynamic/common/generate_immutable_dynamic_nearest_one.rs:123:21 | 123 | array_init::array_init(|i| | ^^^^^^^^^^^^^^^^^^^^^^ the trait `rkyv::Archive` is not implemented for `aligned_vec::AVec<A, aligned_vec::ConstAlign<128>>` | ::: src/immutable_dynamic/float/query/nearest_one.rs:64:5 | 64 | / generate_immutable_dynamic_float_nearest_one!( 65 | | "use std::fs::File; 66 | | use memmap::MmapOptions; ... | 69 | | let tree = unsafe { rkyv::archived_root::<ImmutableDynamicKdTree<f64, 3>>(&mmap) };" 70 | | ); | |_____- in this macro invocation | = help: the following other types implement trait `rkyv::Archive`: () (T0,) (T1, T0) (T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0) (T2, T1, T0) (T3, T2, T1, T0) (T4, T3, T2, T1, T0) and 81 others note: required by a bound in `immutable_dynamic::float::kdtree::ArchivedImmutableDynamicKdTree` --> src/immutable_dynamic/float/kdtree.rs:45:12 | 45 | derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) | ^^^^^^^^^^^^^ required by this bound in `ArchivedImmutableDynamicKdTree` ... 48 | pub struct ImmutableDynamicKdTree< | ---------------------- required by a bound in this struct = note: this error originates in the macro `generate_immutable_dynamic_nearest_one` which comes from the expansion of the derive macro `rkyv::Archive` (in Nightly builds, run with -Z macro-backtrace for more info)
&self.leaf_points[i][leaf_extent.start as usize..leaf_extent.end as usize]
&self.leaf_points[i][start as usize..end as usize]
),
&self.leaf_items[leaf_extent.start as usize..leaf_extent.end as usize],
&self.leaf_items[start as usize..end as usize],
);

let mut best_item = nearest.item;
let mut best_dist = nearest.distance;

leaf_slice.nearest_one::<D>(
query,
&mut best_dist,
&mut best_item
&mut nearest.distance,
&mut nearest.item
);

nearest.distance = best_dist;
nearest.item = best_item;
}
}
};
Expand Down
Loading

0 comments on commit 5424739

Please sign in to comment.