Skip to content

Commit 43003a4

Browse files
Expose map multiplication method and add exponential forgetting example
1 parent a815bc0 commit 43003a4

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

examples/python/edit/multiply_map.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
import pywavemap as wave
3+
4+
# Load the map
5+
user_home = os.path.expanduser('~')
6+
input_map_path = os.path.join(user_home, "your_map.wvmp")
7+
your_map = wave.Map.load(input_map_path)
8+
9+
# Use the multiply method to implement exponential forgetting
10+
decay_factor = 0.9
11+
wave.edit.multiply(your_map, decay_factor)
12+
13+
# Save the map
14+
output_map_path = os.path.join(user_home, "your_map_decayed.wvmp")
15+
your_map.store(output_map_path)

library/python/src/edit.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <wavemap/core/map/hashed_chunked_wavelet_octree.h>
77
#include <wavemap/core/map/hashed_wavelet_octree.h>
88
#include <wavemap/core/utils/edit/crop.h>
9+
#include <wavemap/core/utils/edit/multiply.h>
910

1011
using namespace nb::literals; // NOLINT
1112

@@ -28,5 +29,21 @@ void add_edit_module(nb::module_& m_edit) {
2829
std::make_shared<ThreadPool>());
2930
},
3031
"map"_a, "center_point"_a, "radius"_a, "termination_height"_a = 0);
32+
33+
// Map multiply methods
34+
// NOTE: Among others, this can be used to implement exponential forgetting,
35+
// by multiplying the map with a scalar between 0 and 1.
36+
m_edit.def(
37+
"multiply",
38+
[](HashedWaveletOctree& map, FloatingPoint multiplier) {
39+
edit::multiply(map, multiplier, std::make_shared<ThreadPool>());
40+
},
41+
"map"_a, "multiplier"_a);
42+
m_edit.def(
43+
"multiply",
44+
[](HashedChunkedWaveletOctree& map, FloatingPoint multiplier) {
45+
edit::multiply(map, multiplier, std::make_shared<ThreadPool>());
46+
},
47+
"map"_a, "multiplier"_a);
3148
}
3249
} // namespace wavemap

0 commit comments

Comments
 (0)