Skip to content

Commit

Permalink
Expose map multiplication method and add exponential forgetting example
Browse files Browse the repository at this point in the history
  • Loading branch information
victorreijgwart committed Dec 12, 2024
1 parent a815bc0 commit 43003a4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/python/edit/multiply_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import pywavemap as wave

# Load the map
user_home = os.path.expanduser('~')
input_map_path = os.path.join(user_home, "your_map.wvmp")
your_map = wave.Map.load(input_map_path)

# Use the multiply method to implement exponential forgetting
decay_factor = 0.9
wave.edit.multiply(your_map, decay_factor)

# Save the map
output_map_path = os.path.join(user_home, "your_map_decayed.wvmp")
your_map.store(output_map_path)
17 changes: 17 additions & 0 deletions library/python/src/edit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <wavemap/core/map/hashed_chunked_wavelet_octree.h>
#include <wavemap/core/map/hashed_wavelet_octree.h>
#include <wavemap/core/utils/edit/crop.h>
#include <wavemap/core/utils/edit/multiply.h>

using namespace nb::literals; // NOLINT

Expand All @@ -28,5 +29,21 @@ void add_edit_module(nb::module_& m_edit) {
std::make_shared<ThreadPool>());
},
"map"_a, "center_point"_a, "radius"_a, "termination_height"_a = 0);

// Map multiply methods
// NOTE: Among others, this can be used to implement exponential forgetting,
// by multiplying the map with a scalar between 0 and 1.
m_edit.def(
"multiply",
[](HashedWaveletOctree& map, FloatingPoint multiplier) {
edit::multiply(map, multiplier, std::make_shared<ThreadPool>());
},
"map"_a, "multiplier"_a);
m_edit.def(
"multiply",
[](HashedChunkedWaveletOctree& map, FloatingPoint multiplier) {
edit::multiply(map, multiplier, std::make_shared<ThreadPool>());
},
"map"_a, "multiplier"_a);
}
} // namespace wavemap

0 comments on commit 43003a4

Please sign in to comment.