feat: external linear algebra libraries integrations + quantity::magnitude()#802
Merged
Conversation
…y::magnitude()` member function Resolves #301
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds opt-in integrations that let mainstream linear algebra libraries (Eigen, GLM, Blaze) act
directly as
quantityrepresentation types, plus aquantity::magnitude()member for vectorquantities. Resolves #301.
Linear algebra integrations
mp-units/integrations/{eigen,glm,blaze}.h)and named modules (
mp_units.integrations.{eigen,glm,blaze}).__has_include, so it is a harmless no-op when its library isabsent. The adapters only wire up the representation customization points. No user adapter code
is needed, and the libraries' native vector and matrix types are used directly.
cartesian_vectorneeds no plugin, and plaindoubleandintwork asone-dimensional vector representations.
representation_canonical_typecustomization pointMaterializes expression-template results (for example the Eigen and Blaze lazy proxies) into
their concrete type before they are stored in a
quantity, so aquantitynever holds adangling reference to an expired operand.
quantity::magnitude()memberquantitynow supportsmagnitude()directly (themagnitudeCPO finds the member),returning the Euclidean magnitude as a scalar quantity. This removes the need for user-defined
magnitude_ofhelpers.quantity spec down to the unit's kind, because V2 cannot express a dedicated scalar-magnitude
quantity spec. For the same reason, quantity-level
scalar_product()andvector_product()are not provided. They would need to return a different quantity kind, which V2 references
cannot name, so they remain available only on the raw representation.
Packaging
Per-backend CMake targets
mp-units::integrations-<name>are provided for source consumers(
add_subdirectory/ FetchContent) and rawcmake --install. They are intentionally notsurfaced as Conan components (documented in
conanfile.py): Conan consumers linkmp-units::integrationsplus their own linear algebra library.Docs and tests
representation_types.md), the custom-representation how-to guide, and a newannotated example (
docs/examples/linear_algebra.mdwithexample/linear_algebra.cpp)compiled against all backends in both header and module modes.
test/runtime/linear_algebra_test.cppreworked to exercise the integrations and thecompile-time guarantees.
test_packageextended with header-mode integration consumers for each backend.🤖 Generated with Claude Code