Skip to content

Commit dd4dcea

Browse files
authored
Merge pull request #366 from Simple-Robotics/new-allocator-resource
Introduce `mimalloc`-based memory resource
2 parents 779facc + 0da29ea commit dd4dcea

File tree

11 files changed

+144
-33
lines changed

11 files changed

+144
-33
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- gar/blk-matrix : added `BlkMatrix::isApprox()` (https://github.com/Simple-Robotics/aligator/pull/366)
13+
- core : added [mimalloc](https://github.com/mimalloc/mimalloc)-based memory resource (https://github.com/Simple-Robotics/aligator/pull/366)
1214
- modelling/costs : add getter and setter for cost term weights (https://github.com/Simple-Robotics/aligator/pull/359)
1315
- support for Pinocchio 4 (https://github.com/Simple-Robotics/aligator/pull/361)
1416
- added a hash function `ExtendedStringHash` for string types (e.g. `std::string`) which supports transparent/heterogeneous lookup in compatible hash maps (e.g. `boost::unordered_map`) using types other than key type e.g. `std::string_view` (https://github.com/Simple-Robotics/aligator/pull/364)
@@ -17,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1719

1820
### Changed
1921

22+
- tests/gar/block-matrix.cpp : test against BunchKaufman factorization
2023
- move headers `allocator.hpp` and `arena-matrix.hpp` to `aligator/core` dir (https://github.com/Simple-Robotics/aligator/pull/362)
2124
- python: aligator now requires eigenpy version 3.10.3 at least
2225
- python: remove eigenpy version checks

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ ADD_PROJECT_DEPENDENCY(
196196
PKG_CONFIG_REQUIRES "eigen3 >= 3.3.7"
197197
)
198198
ADD_PROJECT_DEPENDENCY(fmt REQUIRED PKG_CONFIG_REQUIRES "fmt >= 10.0.0")
199+
ADD_PROJECT_DEPENDENCY(
200+
mimalloc
201+
REQUIRED
202+
PKG_CONFIG_REQUIRES "mimalloc >= 2.1.0"
203+
)
199204

200205
if(BUILD_WITH_OPENMP_SUPPORT)
201206
ADD_PROJECT_DEPENDENCY(OpenMP REQUIRED)
@@ -363,7 +368,7 @@ function(create_library)
363368
if(BUILD_WITH_OPENMP_SUPPORT)
364369
target_link_libraries(${PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX)
365370
endif()
366-
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt)
371+
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt PRIVATE mimalloc)
367372
# set the install-tree include dirs used by dependent projects to consume this
368373
# target
369374
target_include_directories(

flake.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
./tests
4141
];
4242
};
43+
buildInputs = (super.buildInputs or []) ++ [
44+
pkgs.mimalloc
45+
];
4346
checkInputs = super.checkInputs ++ [
4447
pkgs.catch2_3
4548
];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// @copyright Copyright (C) 2025 INRIA
2+
#pragma once
3+
4+
#include <memory_resource>
5+
6+
namespace aligator {
7+
8+
/// @brief A memory_resource wrapping around mimalloc.
9+
class mimalloc_resource : public std::pmr::memory_resource {
10+
public:
11+
mimalloc_resource() = default;
12+
13+
private:
14+
[[nodiscard]] void *do_allocate(size_t bytes, size_t alignment) override;
15+
16+
void do_deallocate(void *ptr, size_t bytes, size_t alignment) override;
17+
18+
bool do_is_equal(const memory_resource &other) const noexcept override {
19+
// Check if 'other' is also a mimalloc_resource
20+
return dynamic_cast<const mimalloc_resource *>(&other) != nullptr;
21+
}
22+
};
23+
24+
} // namespace aligator

include/aligator/gar/blk-matrix.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ template <typename _MatrixType, int _N, int _M> class BlkMatrix {
171171
MatrixType &matrix() { return m_data; }
172172
const MatrixType &matrix() const { return m_data; }
173173

174+
template <typename D>
175+
inline bool isApprox(
176+
const Eigen::EigenBase<D> &other,
177+
const Scalar prec = Eigen::NumTraits<Scalar>::dummy_precision()) const {
178+
return matrix().isApprox(other, prec);
179+
}
180+
181+
template <typename D, int N2, int M2>
182+
inline bool isApprox(
183+
const BlkMatrix<D, N2, M2> &other,
184+
const Scalar prec = Eigen::NumTraits<Scalar>::dummy_precision()) const {
185+
return matrix().isApprox(other.matrix(), prec);
186+
}
187+
174188
const RowDimsType &rowDims() const { return m_rowDims; }
175189
const RowDimsType &rowIndices() const { return m_rowIndices; }
176190
const ColDimsType &colDims() const { return m_colDims; }
@@ -179,6 +193,7 @@ template <typename _MatrixType, int _N, int _M> class BlkMatrix {
179193
Index rows() const { return m_totalRows; }
180194
Index cols() const { return m_totalCols; }
181195

196+
/// @brief Take the top \c n block rows of the block matrix.
182197
auto topBlkRows(size_t n) {
183198
using OutType = BlkMatrix<Eigen::Ref<MatrixType>, -1, M>;
184199
std::vector<Index> subRowDims;
@@ -188,6 +203,8 @@ template <typename _MatrixType, int _N, int _M> class BlkMatrix {
188203
return OutType(m_data.topRows(ntr), subRowDims, m_colDims);
189204
}
190205

206+
/// @copybrief topBlkRows().
207+
/// This version returns a fixed-size block.
191208
template <size_t n> auto topBlkRows() {
192209
static_assert(n <= N,
193210
"Cannot take n block rows of matrix with <n block rows.");

0 commit comments

Comments
 (0)