Skip to content

Commit fcd93bf

Browse files
committed
[ext] proposed eigen format printing
1 parent 73b844c commit fcd93bf

File tree

7 files changed

+30
-13
lines changed

7 files changed

+30
-13
lines changed

examples/nucleo_g474re/eigen/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
using namespace Board;
1515

16+
Eigen::IOFormat squarebrackets(5, 0, ", ", "\n", "[", "]");
17+
1618
int
1719
main()
1820
{
@@ -30,7 +32,7 @@ main()
3032
MODM_LOG_INFO << "Here is u*v^T:\n" << u * v.transpose() << modm::endl;
3133
MODM_LOG_INFO << "Let's multiply mat by itself" << modm::endl;
3234
mat = mat * mat;
33-
MODM_LOG_INFO << "Now mat is mat:\n" << mat << modm::endl;
35+
MODM_LOG_INFO << "Now mat is mat:\n" << mat.format(squarebrackets)<< modm::endl;
3436

3537
modm::delay(1s);
3638
}

examples/nucleo_g474re/eigen/project.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
</options>
66
<modules>
77
<module>modm:build:scons</module>
8+
<module>modm:platform:heap</module>
89
<module>modm:eigen</module>
910
</modules>
1011
</library>

ext/libeigen/Version.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
# include <eigen_conf_local.h>
1717
#endif
1818

19+
%% if eigen_no_io
1920
#define EIGEN_NO_IO
21+
%% endif
2022
#define EIGEN_DONT_VECTORIZE
2123
#define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
2224
#define EIGEN_DONT_PARALLELIZE

ext/libeigen/eigen.lb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ def build(env):
2929
env.outbasepath = "modm/ext/eigen"
3030
env.collect(":build:path.include", "modm/ext/eigen")
3131

32-
env.substitutions = {"eigen_no_malloc": not env.has_module(":platform:heap")}
32+
env.substitutions = {
33+
"eigen_no_malloc": not env.has_module(":platform:heap"),
34+
"eigen_no_io": not (env.has_module(":io") and env.has_module(":platform:heap"))
35+
}
3336
env.copy("eigen/Eigen", "Eigen", ignore=env.ignore_files("Version"))
3437
env.copy("eigen/Eigen/Version", "Eigen/Version_orig")
3538
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")

src/modm/io/iostream.hpp.in

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,20 @@ public:
247247
%% endif
248248

249249

250+
inline size_t width() const { return 0; }
251+
inline void width(size_t) {}
252+
inline size_t precision() const { return fmt_precision; }
253+
inline size_t precision(size_t p) {
254+
size_t old = fmt_precision;
255+
fmt_precision = p;
256+
return old;
257+
}
258+
inline char fill() const { return ' '; }
259+
inline char fill(char) {
260+
return ' ';
261+
}
262+
263+
250264
protected:
251265
template< typename T >
252266
void
@@ -273,7 +287,7 @@ protected:
273287
void writeInteger(uint64_t value);
274288
%% endif
275289

276-
%% if options.with_float
290+
%% if options.with_float and options.with_printf
277291
inline void writeFloat(float value)
278292
{ writeDouble(static_cast<double>(value)); }
279293
void writeDouble(const double& value);
@@ -303,6 +317,9 @@ private:
303317
{ if (c) reinterpret_cast<modm::IOStream*>(arg)->write(c); }
304318
printf_output_gadget_t output_gadget{out_char, this, NULL, 0, INT_MAX};
305319
%% endif
320+
%% if options.with_float and options.with_printf
321+
size_t fmt_precision = 0;
322+
%% endif
306323
};
307324

308325
/// @ingroup modm_io
@@ -372,8 +389,5 @@ white(IOStream& ios);
372389
} // namespace modm
373390

374391
#include "iostream_chrono.hpp"
375-
%% if with_eigen
376-
#include "iostream_eigen.hpp"
377-
%% endif
378392

379393
#endif // MODM_IOSTREAM_HPP

src/modm/io/iostream_printf.cpp.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void
147147
IOStream::writeDouble(const double& value)
148148
{
149149
%% if options.with_printf
150-
print_floating_point(&output_gadget, value, 0, 0, 0, true);
150+
print_floating_point(&output_gadget, value, fmt_precision, 0, 0, true);
151151
%% else
152152
if(!std::isfinite(value)) {
153153
if(std::isinf(value)) {

src/modm/io/module.lb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def build(env):
4848
"is_avr": target.platform == "avr",
4949
"with_fiber": env.has_module(":processing:fiber"),
5050
"family": target.family,
51-
"core": core,
52-
"with_eigen": env.has_module(":eigen"),
51+
"core": core
5352
}
5453
env.outbasepath = "modm/src/modm/io"
5554
env.copy("iodevice.hpp")

0 commit comments

Comments
 (0)