Skip to content

Commit 78ca33f

Browse files
hshosesalkinium
andcommitted
[ext] Add Eigen submodule and integration
Co-authored-by: Niklas Hauser <[email protected]>
1 parent 12bf7e0 commit 78ca33f

File tree

7 files changed

+127
-0
lines changed

7 files changed

+127
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@
5252
[submodule "ext/segger/rtt"]
5353
path = ext/segger/rtt
5454
url = https://github.com/modm-ext/segger-rtt.git
55+
[submodule "ext/libeigen/eigen"]
56+
path = ext/libeigen/eigen
57+
url = https://github.com/modm-ext/eigen-partial.git

ext/libeigen/Version.in

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2025, Henrik Hose
3+
* Copyright (c) 2025, Niklas Hauser
4+
*
5+
* This file is part of the modm project.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
10+
*/
11+
// ----------------------------------------------------------------------------
12+
13+
#pragma once
14+
15+
#if __has_include(<eigen_conf_local.h>)
16+
# include <eigen_conf_local.h>
17+
#endif
18+
19+
#define EIGEN_NO_IO
20+
#define EIGEN_DONT_VECTORIZE
21+
#define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
22+
#define EIGEN_DONT_PARALLELIZE
23+
24+
#define EIGEN_MALLOC_ALREADY_ALIGNED 1
25+
#ifndef EIGEN_MAX_ALIGN_BYTES
26+
#define EIGEN_MAX_ALIGN_BYTES 0
27+
#endif
28+
#ifndef EIGEN_MAX_STATIC_ALIGN_BYTES
29+
#define EIGEN_MAX_STATIC_ALIGN_BYTES 4
30+
#endif
31+
%#
32+
%% if eigen_no_malloc
33+
#define EIGEN_NO_MALLOC
34+
%% endif
35+
#ifndef EIGEN_STACK_ALLOCATION_LIMIT
36+
#define EIGEN_STACK_ALLOCATION_LIMIT 1024
37+
#endif
38+
39+
#ifndef MODM_DEBUG_BUILD
40+
#define EIGEN_NO_DEBUG
41+
#endif
42+
43+
#include <modm/architecture/interface/assert.hpp>
44+
45+
#define eigen_assert(cond) \
46+
modm_assert(cond, "eigen", __FILE__ ":" MODM_STRINGIFY(__LINE__) " -> \"" #cond "\"")
47+
48+
#include "Version_orig"

ext/libeigen/eigen

Submodule eigen added at 4d259ca

ext/libeigen/eigen.lb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2025, Henrik Hose
5+
# Copyright (c) 2025, Niklas Hauser
6+
#
7+
# This file is part of the modm project.
8+
#
9+
# This Source Code Form is subject to the terms of the Mozilla Public
10+
# License, v. 2.0. If a copy of the MPL was not distributed with this
11+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
12+
# -----------------------------------------------------------------------------
13+
14+
def init(module):
15+
module.name = ":eigen"
16+
module.description = """
17+
# Eigen Linear Algebra Library
18+
19+
20+
"""
21+
22+
23+
def prepare(module, options):
24+
module.depends(":architecture:assert")
25+
return True
26+
27+
28+
def build(env):
29+
env.outbasepath = "modm/ext/eigen"
30+
env.collect(":build:path.include", "modm/ext/eigen")
31+
32+
env.substitutions = {"eigen_no_malloc": not env.has_module(":platform:heap")}
33+
env.copy("eigen/Eigen", "Eigen", ignore=env.ignore_files("Version"))
34+
env.copy("eigen/Eigen/Version", "Eigen/Version_orig")
35+
env.template("Version.in", "Eigen/Version")
36+
37+
if env.has_module(":io"):
38+
env.outbasepath = "modm/src/modm/io"
39+
env.copy("iostream_eigen.hpp")

ext/libeigen/iostream_eigen.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2025, Henrik Hose
3+
* Copyright (c) 2025, Niklas Hauser
4+
*
5+
* This file is part of the modm project.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
10+
*/
11+
// ----------------------------------------------------------------------------
12+
13+
#pragma once
14+
#include <Eigen/Dense>
15+
16+
namespace modm
17+
{
18+
19+
template<typename Derived>
20+
modm::IOStream& operator<<(modm::IOStream& s, const Eigen::MatrixBase<Derived>& m)
21+
{
22+
for (Eigen::Index r = 0; r < m.rows(); ++r) {
23+
for (Eigen::Index c = 0; c < m.cols(); ++c) {
24+
s << m(r, c);
25+
if (c + 1 < m.cols()) s << ", ";
26+
}
27+
if (r + 1 < m.rows()) s << "\n";
28+
}
29+
return s;
30+
}
31+
32+
} // namespace modm

src/modm/io/iostream.hpp.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,5 +372,8 @@ white(IOStream& ios);
372372
} // namespace modm
373373

374374
#include "iostream_chrono.hpp"
375+
%% if with_eigen
376+
#include "iostream_eigen.hpp"
377+
%% endif
375378

376379
#endif // MODM_IOSTREAM_HPP

src/modm/io/module.lb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def build(env):
4949
"with_fiber": env.has_module(":processing:fiber"),
5050
"family": target.family,
5151
"core": core,
52+
"with_eigen": env.has_module(":eigen"),
5253
}
5354
env.outbasepath = "modm/src/modm/io"
5455
env.copy("iodevice.hpp")

0 commit comments

Comments
 (0)