-
Notifications
You must be signed in to change notification settings - Fork 155
Adding Eigen Linear Algebra support #1302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hshose
wants to merge
7
commits into
modm-io:develop
Choose a base branch
from
hshose:feature/eigen
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3d252fa
[assert] Remove dependency on Register implementation
salkinium 0cf3706
[io] Implement floating point precision for printf
hshose 306a62a
[ext] Add Eigen submodule and integration
hshose 5f91569
[examples] Add Eigen matrix example
hshose 3a9cae0
fixup! [ext] Add Eigen submodule and integration
salkinium c4dd6dd
fixup! [io] Implement floating point precision for printf
salkinium b63a5c0
fixup! [examples] Add Eigen matrix example
salkinium File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Copyright (c) 2025, Henrik Hose | ||
| * | ||
| * This file is part of the modm project. | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
|
|
||
| #include <modm/board.hpp> | ||
| #include <Eigen/Eigen> | ||
|
|
||
| using namespace Board; | ||
|
|
||
| Eigen::IOFormat squarebrackets(5, 0, ", ", "\n", "[", "]"); | ||
|
|
||
| int | ||
| main() | ||
| { | ||
| Board::initialize(); | ||
| LedD13::setOutput(); | ||
|
|
||
| while (1) | ||
| { | ||
| Eigen::Matrix2f mat{{1, 2}, {3, 4}}; | ||
| Eigen::Vector2f u{-1, 1}, v{2, 0}; | ||
| MODM_LOG_INFO << "Here is mat*mat:\n" << mat * mat << modm::endl; | ||
| MODM_LOG_INFO << "Here is mat*u:\n" << mat * u << modm::endl; | ||
| MODM_LOG_INFO << "Here is u^T*mat:\n" << u.transpose() * mat << modm::endl; | ||
| MODM_LOG_INFO << "Here is u^T*v:\n" << u.transpose() * v << modm::endl; | ||
| MODM_LOG_INFO << "Here is u*v^T:\n" << u * v.transpose() << modm::endl; | ||
| MODM_LOG_INFO << "Let's multiply mat by itself" << modm::endl; | ||
| mat = mat * mat; | ||
| MODM_LOG_INFO << "Now mat is mat:\n" << mat.format(squarebrackets)<< modm::endl; | ||
|
|
||
| modm::delay(1s); | ||
| } | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <library> | ||
| <extends>modm:nucleo-g474re</extends> | ||
| <options> | ||
| <option name="modm:build:build.path">../../../build/nucleo_g474re/eigen</option> | ||
| </options> | ||
| <modules> | ||
| <module>modm:build:scons</module> | ||
| <module>modm:platform:heap</module> | ||
| <module>modm:eigen</module> | ||
| </modules> | ||
| </library> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Copyright (c) 2025, Henrik Hose | ||
| * Copyright (c) 2025, Niklas Hauser | ||
| * | ||
| * This file is part of the modm project. | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| #pragma once | ||
|
|
||
| #if __has_include(<modm_conf_eigen.h>) | ||
| # include <modm_conf_eigen.h> | ||
| #endif | ||
| %% if with_io | ||
| #include <modm/io.hpp> | ||
| %# | ||
| %% else | ||
| %# | ||
| #define EIGEN_NO_IO | ||
| %% endif | ||
| #define EIGEN_DONT_VECTORIZE | ||
| #define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT | ||
| #define EIGEN_DONT_PARALLELIZE | ||
|
|
||
| #define EIGEN_MALLOC_ALREADY_ALIGNED 1 | ||
| #ifndef EIGEN_MAX_ALIGN_BYTES | ||
| #define EIGEN_MAX_ALIGN_BYTES 0 | ||
| #endif | ||
| #ifndef EIGEN_MAX_STATIC_ALIGN_BYTES | ||
| #define EIGEN_MAX_STATIC_ALIGN_BYTES 4 | ||
| #endif | ||
| %# | ||
| %% if not with_heap | ||
| #define EIGEN_NO_MALLOC | ||
| %% endif | ||
| #ifndef EIGEN_STACK_ALLOCATION_LIMIT | ||
| #define EIGEN_STACK_ALLOCATION_LIMIT 1024 | ||
| #endif | ||
|
|
||
| #ifndef MODM_DEBUG_BUILD | ||
| #define EIGEN_NO_DEBUG | ||
| #endif | ||
|
|
||
| #include <modm/architecture/interface/assert.hpp> | ||
|
|
||
| #define eigen_assert(cond) \ | ||
| modm_assert(cond, "eigen", __FILE__ ":" MODM_STRINGIFY(__LINE__) " -> \"" #cond "\"") | ||
|
|
||
| #include "Version_orig" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/usr/bin/env python3 | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (c) 2025, Henrik Hose | ||
| # Copyright (c) 2025, Niklas Hauser | ||
| # | ||
| # This file is part of the modm project. | ||
| # | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
| def init(module): | ||
| module.name = ":eigen" | ||
| module.description = FileReader("module.md") | ||
|
|
||
|
|
||
| def prepare(module, options): | ||
| module.depends(":architecture:assert") | ||
| return True | ||
|
|
||
|
|
||
| def build(env): | ||
| env.outbasepath = "modm/ext/eigen" | ||
| env.collect(":build:path.include", "modm/ext/eigen") | ||
|
|
||
| env.substitutions = { | ||
| "with_heap": env.has_module(":platform:heap"), | ||
| "with_io": env.has_module(":io") and env.has_module(":platform:heap"), | ||
| } | ||
| env.copy("eigen/Eigen", "Eigen", ignore=env.ignore_files("Version")) | ||
| env.copy("eigen/Eigen/Version", "Eigen/Version_orig") | ||
| env.template("Version.in", "Eigen/Version") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Eigen Linear Algebra Library | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.