Skip to content

feat: external linear algebra libraries integrations + quantity::magnitude()#802

Merged
mpusz merged 1 commit into
masterfrom
la_integrations
Jun 22, 2026
Merged

feat: external linear algebra libraries integrations + quantity::magnitude()#802
mpusz merged 1 commit into
masterfrom
la_integrations

Conversation

@mpusz

@mpusz mpusz commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Summary

Adds opt-in integrations that let mainstream linear algebra libraries (Eigen, GLM, Blaze) act
directly as quantity representation types, plus a quantity::magnitude() member for vector
quantities. Resolves #301.

Linear algebra integrations

  • New opt-in adapters, available both as headers (mp-units/integrations/{eigen,glm,blaze}.h)
    and named modules (mp_units.integrations.{eigen,glm,blaze}).
  • Each header is guarded with __has_include, so it is a harmless no-op when its library is
    absent. 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.
  • The built-in cartesian_vector needs no plugin, and plain double and int work as
    one-dimensional vector representations.

representation_canonical_type customization point

Materializes expression-template results (for example the Eigen and Blaze lazy proxies) into
their concrete type before they are stored in a quantity, so a quantity never holds a
dangling reference to an expired operand.

quantity::magnitude() member

  • A vector quantity now supports magnitude() directly (the magnitude CPO finds the member),
    returning the Euclidean magnitude as a scalar quantity. This removes the need for user-defined
    magnitude_of helpers.
  • Known V2 limitation, documented in the code and the user guide: the result drops the precise
    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() and vector_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 raw cmake --install. They are intentionally not
surfaced as Conan components (documented in conanfile.py): Conan consumers link
mp-units::integrations plus their own linear algebra library.

Docs and tests

  • User guide (representation_types.md), the custom-representation how-to guide, and a new
    annotated example (docs/examples/linear_algebra.md with example/linear_algebra.cpp)
    compiled against all backends in both header and module modes.
  • test/runtime/linear_algebra_test.cpp reworked to exercise the integrations and the
    compile-time guarantees.
  • test_package extended with header-mode integration consumers for each backend.

🤖 Generated with Claude Code

@mpusz mpusz merged commit 5c8c4ad into master Jun 22, 2026
200 checks passed
@mpusz mpusz deleted the la_integrations branch June 22, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[request] Example using Eigen

1 participant