-
Notifications
You must be signed in to change notification settings - Fork 11
Rust support for code generation #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2681464
refactor: separate cmake and build steps in Dockerfile
claytonwramsey 3576dba
feat: support Rust code generation in cricket
claytonwramsey 5e22fe6
refactor: move error handling into sphere tracing procedure
claytonwramsey a7bfda0
refactor: merge cmake steps back together
claytonwramsey 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,5 @@ | |
| /output.data | ||
| /output.json | ||
| /*.hh | ||
| /*.rs | ||
| /.cpm-cache/ | ||
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,81 @@ | ||
| {% for i in range(length(links_with_geometry)) %} | ||
| {% set array_index = length(links_with_geometry) - i - 1 %} | ||
| {% set link_index = at(links_with_geometry, array_index) %} | ||
| {% set link_spheres = at(per_link_spheres, link_index) %} | ||
| {% set bs_loc = (n_spheres + array_index) * 4 %} | ||
|
|
||
| // | ||
| // environment vs. robot collisions | ||
| // | ||
|
|
||
| // {{ at(link_names, link_index) }} | ||
| if sphere_environment_in_collision(environment, | ||
| y[{{bs_loc + 0}}], | ||
| y[{{bs_loc + 1}}], | ||
| y[{{bs_loc + 2}}], | ||
| y[{{bs_loc + 3}}]) | ||
| { | ||
| {% for j in range(length(link_spheres)) %} | ||
| {% set sphere_loc = at(link_spheres, j) * 4 %} | ||
| if sphere_environment_in_collision(environment, | ||
| y[{{ sphere_loc + 0 }}], | ||
| y[{{ sphere_loc + 1 }}], | ||
| y[{{ sphere_loc + 2 }}], | ||
| y[{{ sphere_loc + 3 }}]) | ||
| { | ||
| return false; | ||
| } | ||
| {% endfor %} | ||
| } | ||
|
|
||
| {% endfor %} | ||
|
|
||
| // | ||
| // robot self-collisions | ||
| // | ||
|
|
||
| {% for i in range(length(allowed_link_pairs)) %} | ||
| {% set pair = at(allowed_link_pairs, i) %} | ||
| {% set link_1_index = at(pair, 0) %} | ||
| {% set link_2_index = at(pair, 1) %} | ||
| {% set link_1_bs = at(bounding_sphere_index, link_1_index) %} | ||
| {% set link_2_bs = at(bounding_sphere_index, link_2_index) %} | ||
| {% set link_1_spheres = at(per_link_spheres, link_1_index) %} | ||
| {% set link_2_spheres = at(per_link_spheres, link_2_index) %} | ||
| {% set link_1_bs_loc = (n_spheres + link_1_bs) * 4 %} | ||
| {% set link_2_bs_loc = (n_spheres + link_2_bs) * 4 %} | ||
|
|
||
| // {{ at(link_names, link_1_index) }} vs. {{ at(link_names, link_2_index) }} | ||
| if sphere_sphere_self_collision( | ||
| y[{{link_1_bs_loc + 0}}], | ||
| y[{{link_1_bs_loc + 1}}], | ||
| y[{{link_1_bs_loc + 2}}], | ||
| y[{{link_1_bs_loc + 3}}], | ||
| y[{{link_2_bs_loc + 0}}], | ||
| y[{{link_2_bs_loc + 1}}], | ||
| y[{{link_2_bs_loc + 2}}], | ||
| y[{{link_2_bs_loc + 3}}] | ||
| ) { | ||
| {% for j in range(length(link_1_spheres)) %} | ||
| {% for k in range(length(link_2_spheres)) %} | ||
|
|
||
| {% set sphere_1_loc = at(link_1_spheres, j) %} | ||
| {% set sphere_2_loc = at(link_2_spheres, k) %} | ||
|
|
||
| if sphere_sphere_self_collision( | ||
| y[{{ sphere_1_loc * 4 + 0}} ], | ||
| y[{{ sphere_1_loc * 4 + 1}} ], | ||
| y[{{ sphere_1_loc * 4 + 2}} ], | ||
| y[{{ sphere_1_loc * 4 + 3}} ], | ||
| y[{{ sphere_2_loc * 4 + 0}} ], | ||
| y[{{ sphere_2_loc * 4 + 1}} ], | ||
| y[{{ sphere_2_loc * 4 + 2}} ], | ||
| y[{{ sphere_2_loc * 4 + 3}} ] | ||
| ) { | ||
| return false; | ||
| } | ||
|
|
||
| {% endfor %} | ||
| {% endfor %} | ||
| } | ||
| {% endfor %} |
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,29 @@ | ||
| use core::simd::Simd; | ||
|
|
||
| use elain::{Align, Alignment}; | ||
|
|
||
| use crate::{ | ||
| env::World3d, | ||
| robot::{sphere_environment_in_collision, sphere_sphere_self_collision}, | ||
| cos, sin, | ||
| }; | ||
|
|
||
| #[expect( | ||
| non_snake_case, | ||
| clippy::too_many_lines, | ||
| clippy::cognitive_complexity, | ||
| clippy::unreadable_literal, | ||
| clippy::approx_constant, | ||
| clippy::collapsible_if | ||
| )] | ||
| pub fn fkcc<const L: usize>(x: &super::ConfigurationBlock<L>, environment: &World3d<f32, L>) -> bool | ||
| where | ||
| Align<L>: Alignment, | ||
| { | ||
| let mut v = [Simd::splat(0.0); {{ccfk_code_vars}}]; | ||
| let mut y = [Simd::splat(0.0); {{ccfk_code_output}}]; | ||
|
|
||
| {{ccfk_code}} | ||
| {% include "ccfk" %} | ||
| true | ||
| } |
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
File renamed without changes.
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,51 @@ | ||
| #pragma once | ||
|
|
||
| #include <iomanip> | ||
| #include "cppad/cg/lang/c/language_c.hpp" | ||
|
|
||
| namespace CppAD | ||
| { | ||
| namespace cg | ||
| { | ||
|
|
||
| template <class Base> | ||
| class LanguageRust : public LanguageC<Base> | ||
| { | ||
| public: | ||
| explicit LanguageRust(std::string varTypeName, size_t spaces = 3) | ||
| : LanguageC<Base>(varTypeName, spaces) | ||
| { | ||
| } | ||
|
|
||
| virtual void printParameter(const Base &value) | ||
| { | ||
| writeParameter(value, LanguageRust<Base>::_code); | ||
| } | ||
|
|
||
| virtual void pushParameter(const Base &value) | ||
| { | ||
| writeParameter(value, LanguageRust<Base>::_streamStack); | ||
| } | ||
|
|
||
| template <class Output> | ||
| void writeParameter(const Base &value, Output &output) | ||
| { | ||
| // make sure all digits of floating point values are printed | ||
| std::ostringstream os; | ||
| os << std::setprecision(LanguageRust<Base>::_parameterPrecision) << value; | ||
|
|
||
| std::string number = os.str(); | ||
| output << "Simd::<f32, L>::splat("; | ||
| output << number; | ||
|
|
||
| if (number.find('.') == std::string::npos && number.find('e') == std::string::npos) | ||
| { | ||
| // also make sure there is always a '.' after the number in | ||
| // order to avoid integer overflows | ||
| output << '.'; | ||
| } | ||
| output << ")"; | ||
| } | ||
| }; | ||
| } // namespace cg | ||
| } // namespace CppAD |
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.