Skip to content

Conversation

@calcmogul
Copy link
Member

@calcmogul calcmogul commented Sep 20, 2025

The wrapper includes reverse mode autodiff, the Problem DSL, and the optimal control problem API. I wrote it by directly translating the upstream API and tests to Java (i.e., copy-paste-modify).

I replaced the ArmFeedforward and Ellipse2d JNIs with implementations using the Sleipnir Java bindings. Switching dev binary JNIs to release by default sped up wpimath test runs from several minutes to 7 seconds.

@github-actions github-actions bot added the component: wpimath Math library label Sep 20, 2025
@calcmogul calcmogul force-pushed the wpimath-add-sleipnir-java-bindings branch 29 times, most recently from 7e667cd to 9749bdc Compare September 22, 2025 04:37
@calcmogul calcmogul force-pushed the wpimath-add-sleipnir-java-bindings branch 13 times, most recently from 4fa1899 to db70c2c Compare November 11, 2025 01:10
@calcmogul calcmogul marked this pull request as draft November 11, 2025 02:21
@calcmogul calcmogul force-pushed the wpimath-add-sleipnir-java-bindings branch 4 times, most recently from 41dccd2 to ef6b153 Compare November 11, 2025 20:15
Comment on lines +47 to +48
public VariableMatrix(int rows) {
this(rows, 1);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better as a static, named factory like VariableMatrix.columnVector(int rows)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent was to be consistent with the EJML matrix API, in the same way the C++ API mirrors Eigen.

@calcmogul calcmogul force-pushed the wpimath-add-sleipnir-java-bindings branch from 7021ce3 to e8a15e7 Compare November 12, 2025 04:45
@github-actions github-actions bot removed the component: wpiutil WPI utility library label Nov 12, 2025
@calcmogul calcmogul force-pushed the wpimath-add-sleipnir-java-bindings branch from e8a15e7 to 3cde4f4 Compare November 12, 2025 04:49
@calcmogul
Copy link
Member Author

calcmogul commented Nov 12, 2025

One big problem this PR still needs solved is how to track the Variables created by intermediate expressions, and how to ensure their native handles are freed in a timely manner so the JVM doesn't OOM. try-with-resources isn't applicable to those, and Cleaners aren't guaranteed to run since the JVM doesn't know how much space native objects take up.

The only thing I could think of was a factory object, whether that's Problem for free variables in addition to decision variables, or a separate factory class for the autodiff use case. Each Variable would need to keep track of its source factory so new intermediate Variables can be allocated from it. Try-with-resources on the factory would clean things up.

@calcmogul calcmogul force-pushed the wpimath-add-sleipnir-java-bindings branch 4 times, most recently from 4067405 to 2332858 Compare November 17, 2025 22:28
@calcmogul calcmogul force-pushed the wpimath-add-sleipnir-java-bindings branch from 2332858 to dca5749 Compare November 25, 2025 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2027 2027 target component: wpimath Math library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java wrapper for Sleipnir

3 participants