Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: rework cmap2 index & attribute system #36

Merged
merged 31 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
512fc22
refactor: remove useless field for the new impl
imrn99 Apr 12, 2024
a8442c7
refactor: update CMap2 constructor
imrn99 Apr 12, 2024
e0bd812
refactor: update orbits content
imrn99 Apr 12, 2024
95ee726
refacto: copy paste the content of the rework-icells branch
imrn99 Apr 12, 2024
716ec92
chore: update imports in twomap module
imrn99 Apr 12, 2024
5cc40dd
feat: add collection types for i-cells
imrn99 Apr 12, 2024
5302e73
fix: update some of the vertex related methods of CMap2
imrn99 Apr 12, 2024
574f56f
refactor: adjust size methods
imrn99 Apr 12, 2024
4e3621c
refactor: update generation mod & constructor sig
imrn99 Apr 12, 2024
3136288
refactor: change replace method behavior
imrn99 Apr 12, 2024
d01bc3e
refactor: rename CMap2::set_vertex to replace_vertex
imrn99 Apr 12, 2024
5e555b4
refactor: remove old CMap2 example
imrn99 Apr 12, 2024
1c007f6
refactor: update render handle code
imrn99 Apr 12, 2024
bcc05e1
fix: remove unecessary iterator copy in handle code
imrn99 Apr 15, 2024
4758fce
fix: update benchmark code
imrn99 Apr 15, 2024
0746728
fix: update splitsquaremap shift benchmark
imrn99 Apr 15, 2024
59ecf1e
fix: finish benchmark code updates
imrn99 Apr 15, 2024
af51813
refactor: update one/two_sew methods to use the new system
imrn99 Apr 15, 2024
5202e4e
refactor: rewrite unsew methods
imrn99 Apr 15, 2024
7279af4
refactor: update sew methods signature
imrn99 Apr 15, 2024
fdd6f06
fix: update (un)sew usagesto match signature
imrn99 Apr 15, 2024
4ed255f
fix: rewrite on unsew to use Attr::split
imrn99 Apr 15, 2024
78fa546
fix: change map size back to original value in benches
imrn99 Apr 15, 2024
e89f4fa
feat: add back the orientation check to two_sew
imrn99 Apr 15, 2024
3eb40c2
feat: complete size methods of attribute storage structs
imrn99 Apr 15, 2024
831080e
refactor: move the length+1 op to CMap2::new() from the storages
imrn99 Apr 16, 2024
f75efab
refactor: remove useless CMapError variant & add doc
imrn99 Apr 16, 2024
90e7cfd
doc: add doc & comment about the new ID computation
imrn99 Apr 16, 2024
9460d80
doc: adjust CMap2::i_cell doc to better reflect return type
imrn99 Apr 16, 2024
decb9ac
refactor: rename phantom data attribute in cell collections structs
imrn99 Apr 16, 2024
cd1a7d2
doc: add explanation on safe vertex removal in core/editing bench
imrn99 Apr 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 10 additions & 58 deletions honeycomb-benches/benches/core/cmap2/editing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

// ------ IMPORTS

use honeycomb_core::{
utils::square_cmap2, CMap2, DartIdentifier, FaceIdentifier, FloatType, Vertex2,
VertexIdentifier,
};
use honeycomb_core::{utils::square_cmap2, CMap2, DartIdentifier, FloatType};
use iai_callgrind::{
library_benchmark, library_benchmark_group, main, FlamegraphConfig, LibraryBenchmarkConfig,
};
Expand All @@ -33,18 +30,18 @@ fn get_sparse_map(n_square: usize) -> CMap2<FloatType> {
let mut map = square_cmap2::<FloatType>(n_square);
map.set_betas(5, [0; 3]); // free dart 5
map.remove_free_dart(5);
map.remove_vertex(1);
map.remove_vertex(1).unwrap();
imrn99 marked this conversation as resolved.
Show resolved Hide resolved
map
}

fn compute_dims(n_square: usize) -> (usize, usize) {
(n_square.pow(2) * 4, (n_square + 1).pow(2))
fn compute_dims(n_square: usize) -> usize {
n_square.pow(2) * 4
}

#[library_benchmark]
#[benches::with_setup(args = [16, 32, 64, 128, 256, 512], setup = compute_dims)]
fn constructor((n_darts, n_vertices): (usize, usize)) -> CMap2<FloatType> {
black_box(CMap2::new(n_darts, n_vertices))
fn constructor(n_darts: usize) -> CMap2<FloatType> {
black_box(CMap2::new(n_darts))
}

#[library_benchmark]
Expand All @@ -63,39 +60,12 @@ fn add_ten_darts(map: &mut CMap2<FloatType>) -> DartIdentifier {
black_box(map.add_free_darts(10))
}

#[library_benchmark]
#[bench::small(&mut get_map(5))]
#[bench::medium(&mut get_map(50))]
#[bench::large(&mut get_map(500))]
fn add_default_vertex(map: &mut CMap2<FloatType>) -> VertexIdentifier {
black_box(map.add_vertex(None))
}

#[library_benchmark]
#[bench::small(&mut get_map(5))]
#[bench::medium(&mut get_map(50))]
#[bench::large(&mut get_map(500))]
fn add_vertex(map: &mut CMap2<FloatType>) -> VertexIdentifier {
black_box(map.add_vertex(Some(Vertex2::from((12.0, 6.0)))))
}

#[library_benchmark]
#[bench::small(&mut get_map(5))]
#[bench::medium(&mut get_map(50))]
#[bench::large(&mut get_map(500))]
fn add_10_vertices(map: &mut CMap2<FloatType>) -> VertexIdentifier {
black_box(map.add_vertices(10))
}

library_benchmark_group!(
name = bench_new;
benchmarks =
constructor,
add_single_dart,
add_ten_darts,
add_default_vertex,
add_vertex,
add_10_vertices,
);

#[library_benchmark]
Expand All @@ -118,16 +88,8 @@ fn insert_dart_full(map: &mut CMap2<FloatType>) -> DartIdentifier {
#[bench::small(&mut get_sparse_map(5))]
#[bench::medium(&mut get_sparse_map(50))]
#[bench::large(&mut get_sparse_map(500))]
fn insert_vertex(map: &mut CMap2<FloatType>) -> VertexIdentifier {
black_box(map.insert_vertex(None))
}

#[library_benchmark]
#[bench::small(&mut get_map(5))]
#[bench::medium(&mut get_map(50))]
#[bench::large(&mut get_map(500))]
fn insert_vertex_full(map: &mut CMap2<FloatType>) -> VertexIdentifier {
black_box(map.insert_vertex(None))
fn insert_vertex(map: &mut CMap2<FloatType>) {
black_box(map.insert_vertex(1, (0.0, 0.0)));
}

library_benchmark_group!(
Expand All @@ -136,29 +98,19 @@ library_benchmark_group!(
insert_dart,
insert_dart_full,
insert_vertex,
insert_vertex_full,
);

#[library_benchmark]
#[bench::small(&mut get_map(5))]
#[bench::medium(&mut get_map(50))]
#[bench::large(&mut get_map(500))]
fn build_face(map: &mut CMap2<FloatType>) -> FaceIdentifier {
black_box(map.build_face(5))
}

#[library_benchmark]
#[bench::small(&mut get_map(5))]
#[bench::medium(&mut get_map(50))]
#[bench::large(&mut get_map(500))]
fn build_faces(map: &mut CMap2<FloatType>) -> usize {
black_box(map.build_all_faces())
fn build_faces(map: &mut CMap2<FloatType>) {
black_box(map.fetch_faces());
}

library_benchmark_group!(
name = bench_face_building;
benchmarks =
build_face,
build_faces,
);

Expand Down
12 changes: 6 additions & 6 deletions honeycomb-benches/benches/core/cmap2/reading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,24 @@ library_benchmark_group!(
#[bench::small(&get_map(5))]
#[bench::medium(&get_map(50))]
#[bench::large(&get_map(500))]
fn zero_cell(map: &CMap2<FloatType>) -> Vec<DartIdentifier> {
black_box(map.i_cell::<0>(5))
fn zero_cell(map: &CMap2<FloatType>) {
black_box(map.i_cell::<0>(5));
}

#[library_benchmark]
#[bench::small(&get_map(5))]
#[bench::medium(&get_map(50))]
#[bench::large(&get_map(500))]
fn one_cell(map: &CMap2<FloatType>) -> Vec<DartIdentifier> {
black_box(map.i_cell::<0>(5))
fn one_cell(map: &CMap2<FloatType>) {
black_box(map.i_cell::<1>(5));
}

#[library_benchmark]
#[bench::small(&get_map(5))]
#[bench::medium(&get_map(50))]
#[bench::large(&get_map(500))]
fn two_cell(map: &CMap2<FloatType>) -> Vec<DartIdentifier> {
black_box(map.i_cell::<2>(5))
fn two_cell(map: &CMap2<FloatType>) {
black_box(map.i_cell::<2>(5));
}

library_benchmark_group!(
Expand Down
30 changes: 15 additions & 15 deletions honeycomb-benches/benches/core/cmap2/sewing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@

// ------ IMPORTS

use honeycomb_core::{utils::square_cmap2, CMap2, FloatType, SewPolicy, UnsewPolicy};
use honeycomb_core::{utils::square_cmap2, CMap2, FloatType};
use iai_callgrind::{
library_benchmark, library_benchmark_group, main, FlamegraphConfig, LibraryBenchmarkConfig,
};
use std::hint::black_box;

// ------ CONTENT

fn compute_dims(n_square: usize) -> (usize, usize) {
(n_square.pow(2) * 4, (n_square + 1).pow(2))
fn compute_dims(n_square: usize) -> usize {
n_square.pow(2) * 4
}

fn get_map(n_square: usize) -> CMap2<FloatType> {
square_cmap2::<FloatType>(n_square)
}

fn get_unstructured_map(n_square: usize) -> CMap2<FloatType> {
let (n_darts, n_vertices) = compute_dims(n_square);
CMap2::new(n_darts, n_vertices)
let n_darts = compute_dims(n_square);
CMap2::new(n_darts)
}

#[library_benchmark]
#[bench::small(&mut get_unstructured_map(5))]
#[bench::medium(&mut get_unstructured_map(50))]
#[bench::large(&mut get_unstructured_map(500))]
fn one_sew_left(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
map.one_sew(4, 6, SewPolicy::StretchLeft);
map.one_sew(4, 6);
black_box(map)
}

Expand All @@ -50,7 +50,7 @@ fn one_sew_left(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
#[bench::medium(&mut get_unstructured_map(50))]
#[bench::large(&mut get_unstructured_map(500))]
fn one_sew_right(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
map.one_sew(4, 6, SewPolicy::StretchRight);
map.one_sew(4, 6);
black_box(map)
}

Expand All @@ -59,7 +59,7 @@ fn one_sew_right(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
#[bench::medium(&mut get_unstructured_map(50))]
#[bench::large(&mut get_unstructured_map(500))]
fn one_sew_avg(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
map.one_sew(4, 6, SewPolicy::StretchAverage);
map.one_sew(4, 6);
black_box(map)
}

Expand All @@ -76,7 +76,7 @@ library_benchmark_group!(
#[bench::medium(&mut get_unstructured_map(50))]
#[bench::large(&mut get_unstructured_map(500))]
fn two_sew_left(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
map.two_sew(4, 6, SewPolicy::StretchLeft);
map.two_sew(4, 6);
black_box(map)
}

Expand All @@ -85,7 +85,7 @@ fn two_sew_left(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
#[bench::medium(&mut get_unstructured_map(50))]
#[bench::large(&mut get_unstructured_map(500))]
fn two_sew_right(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
map.two_sew(4, 6, SewPolicy::StretchRight);
map.two_sew(4, 6);
black_box(map)
}

Expand All @@ -94,7 +94,7 @@ fn two_sew_right(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
#[bench::medium(&mut get_unstructured_map(50))]
#[bench::large(&mut get_unstructured_map(500))]
fn two_sew_avg(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
map.two_sew(4, 6, SewPolicy::StretchAverage);
map.two_sew(4, 6);
black_box(map)
}

Expand All @@ -111,7 +111,7 @@ library_benchmark_group!(
#[bench::medium(&mut get_map(50))]
#[bench::large(&mut get_map(500))]
fn one_unsew_nothing(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
map.one_unsew(4, UnsewPolicy::DoNothing);
map.one_unsew(4);
black_box(map)
}

Expand All @@ -120,7 +120,7 @@ fn one_unsew_nothing(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
#[bench::medium(&mut get_map(50))]
#[bench::large(&mut get_map(500))]
fn one_unsew_duplicate(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
map.one_unsew(4, UnsewPolicy::Duplicate);
map.one_unsew(4);
black_box(map)
}

Expand All @@ -136,7 +136,7 @@ library_benchmark_group!(
#[bench::medium(&mut get_map(50))]
#[bench::large(&mut get_map(500))]
fn two_unsew_nothing(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
map.two_unsew(4, UnsewPolicy::DoNothing);
map.two_unsew(4);
black_box(map)
}

Expand All @@ -145,7 +145,7 @@ fn two_unsew_nothing(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
#[bench::medium(&mut get_map(50))]
#[bench::large(&mut get_map(500))]
fn two_unsew_duplicate(map: &mut CMap2<FloatType>) -> &mut CMap2<FloatType> {
map.two_unsew(4, UnsewPolicy::Duplicate);
map.two_unsew(4);
black_box(map)
}

Expand Down
28 changes: 17 additions & 11 deletions honeycomb-benches/benches/splitsquaremap/shift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,38 @@ use honeycomb_core::{
// ------ CONTENT

fn offset(mut map: CMap2<FloatType>, offsets: &[Vector2<FloatType>]) {
(0..map.n_vertices().0).for_each(|vertex_id| {
let current_value = map.vertex(vertex_id as DartIdentifier);
let _ = map.set_vertex(
vertex_id as VertexIdentifier,
*current_value + offsets[vertex_id],
let n_offsets = offsets.len();
let vertices = map.fetch_vertices();
vertices.identifiers.iter().for_each(|vertex_id| {
let current_value = map.vertex(*vertex_id as DartIdentifier);
let _ = map.replace_vertex(
*vertex_id as VertexIdentifier,
current_value + offsets[*vertex_id as usize % n_offsets],
);
});
black_box(&mut map);
}

fn offset_if_inner(mut map: CMap2<FloatType>, offsets: &[Vector2<FloatType>]) {
let n_offsets = offsets.len();
let mut inner: BTreeSet<VertexIdentifier> = BTreeSet::new();
let vertices = map.fetch_vertices();
// collect inner vertex IDs
(0..map.n_darts().0 as DartIdentifier).for_each(|dart_id| {
vertices.identifiers.iter().for_each(|vertex_id| {
let neighbors_vertex_cell: Vec<DartIdentifier> = map
.i_cell::<0>(dart_id)
.iter()
.map(|d_id| map.beta::<2>(*d_id))
.i_cell::<0>(*vertex_id as DartIdentifier)
.map(|d_id| map.beta::<2>(d_id))
.collect();
if !neighbors_vertex_cell.contains(&NULL_DART_ID) {
inner.insert(map.vertexid(dart_id));
inner.insert(*vertex_id);
}
});
inner.iter().for_each(|vertex_id| {
let current_value = map.vertex(*vertex_id);
let _ = map.set_vertex(*vertex_id, *current_value + offsets[*vertex_id as usize]);
let _ = map.replace_vertex(
*vertex_id,
current_value + offsets[*vertex_id as usize % n_offsets],
);
});
black_box(&mut map);
}
Expand Down
28 changes: 17 additions & 11 deletions honeycomb-benches/benches/squaremap/shift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,38 @@ use honeycomb_core::{
// ------ CONTENT

fn offset(mut map: CMap2<FloatType>, offsets: &[Vector2<FloatType>]) {
(0..map.n_vertices().0).for_each(|vertex_id| {
let current_value = map.vertex(vertex_id as DartIdentifier);
let _ = map.set_vertex(
vertex_id as VertexIdentifier,
*current_value + offsets[vertex_id],
let n_offsets = offsets.len();
let vertices = map.fetch_vertices();
vertices.identifiers.iter().for_each(|vertex_id| {
let current_value = map.vertex(*vertex_id as DartIdentifier);
let _ = map.replace_vertex(
*vertex_id,
current_value + offsets[*vertex_id as usize % n_offsets],
);
});
black_box(&mut map);
}

fn offset_if_inner(mut map: CMap2<FloatType>, offsets: &[Vector2<FloatType>]) {
let n_offsets = offsets.len();
let vertices = map.fetch_vertices();
let mut inner: BTreeSet<VertexIdentifier> = BTreeSet::new();
// collect inner vertex IDs
(0..map.n_darts().0 as DartIdentifier).for_each(|dart_id| {
vertices.identifiers.iter().for_each(|vertex_id| {
let neighbors_vertex_cell: Vec<DartIdentifier> = map
.i_cell::<0>(dart_id)
.iter()
.map(|d_id| map.beta::<2>(*d_id))
.i_cell::<0>(*vertex_id as DartIdentifier)
.map(|d_id| map.beta::<2>(d_id))
.collect();
if !neighbors_vertex_cell.contains(&NULL_DART_ID) {
inner.insert(map.vertexid(dart_id));
inner.insert(*vertex_id);
}
});
inner.iter().for_each(|vertex_id| {
let current_value = map.vertex(*vertex_id);
let _ = map.set_vertex(*vertex_id, *current_value + offsets[*vertex_id as usize]);
let _ = map.replace_vertex(
*vertex_id,
current_value + offsets[*vertex_id as usize % n_offsets],
);
});
black_box(&mut map);
}
Expand Down
Loading