diff --git a/cxx/include/tensorwrapper/generate/add_noise.hpp b/cxx/include/tensorwrapper/generate/add_noise.hpp index f4215048..a0541986 100644 --- a/cxx/include/tensorwrapper/generate/add_noise.hpp +++ b/cxx/include/tensorwrapper/generate/add_noise.hpp @@ -44,7 +44,14 @@ namespace tensorwrapper::generate { * * @throw std::invalid_argument if @p t is negative. */ -template +// NB: `typename T`, not `concepts::FloatingPoint T`. GCC 14 does not encode a +// template parameter's type-constraint in the mangled name; Clang 18+ does +// (`...ITkN3wtf8concepts13FloatingPointEdE...`). On an explicitly instantiated +// template that yields two different symbols: this library, built by GCC, +// exports the unconstrained name while a Clang consumer asks for the +// constrained one and fails to link. The requirement on T is enforced by a +// static_assert in the definition instead. +template Tensor add_noise(const Tensor& matrix, double t, std::mt19937& gen); /** @brief Overload of add_noise that creates its own RNG from @p seed. @@ -60,7 +67,14 @@ Tensor add_noise(const Tensor& matrix, double t, std::mt19937& gen); * * @throw std::invalid_argument if @p t is negative. */ -template +// NB: `typename T`, not `concepts::FloatingPoint T`. GCC 14 does not encode a +// template parameter's type-constraint in the mangled name; Clang 18+ does +// (`...ITkN3wtf8concepts13FloatingPointEdE...`). On an explicitly instantiated +// template that yields two different symbols: this library, built by GCC, +// exports the unconstrained name while a Clang consumer asks for the +// constrained one and fails to link. The requirement on T is enforced by a +// static_assert in the definition instead. +template Tensor add_noise(const Tensor& matrix, double t, std::uint64_t seed = 42); /** @brief Adds noise with element type `double`. diff --git a/cxx/include/tensorwrapper/generate/generate_eigen_system.hpp b/cxx/include/tensorwrapper/generate/generate_eigen_system.hpp index c78306c4..42410188 100644 --- a/cxx/include/tensorwrapper/generate/generate_eigen_system.hpp +++ b/cxx/include/tensorwrapper/generate/generate_eigen_system.hpp @@ -58,7 +58,14 @@ struct EigenSystem { * * @throw std::invalid_argument if @p spec.n is outside `[1, kMaxMatrixDim]`. */ -template +// NB: `typename T`, not `concepts::FloatingPoint T`. GCC 14 does not encode a +// template parameter's type-constraint in the mangled name; Clang 18+ does +// (`...ITkN3wtf8concepts13FloatingPointEdE...`). On an explicitly instantiated +// template that yields two different symbols: this library, built by GCC, +// exports the unconstrained name while a Clang consumer asks for the +// constrained one and fails to link. The requirement on T is enforced by a +// static_assert in the definition instead. +template EigenSystem generate_eigen_system(const SymmetricMatrixSpec& spec); /** @brief Generates an eigen-system with element type `double`. diff --git a/cxx/include/tensorwrapper/generate/generate_eigenvalues.hpp b/cxx/include/tensorwrapper/generate/generate_eigenvalues.hpp index 86377498..16437747 100644 --- a/cxx/include/tensorwrapper/generate/generate_eigenvalues.hpp +++ b/cxx/include/tensorwrapper/generate/generate_eigenvalues.hpp @@ -45,7 +45,14 @@ namespace tensorwrapper::generate { * @throw std::invalid_argument if @p spec.n is outside `[1, kMaxMatrixDim]` or * if @p spec.spacing is invalid. */ -template +// NB: `typename T`, not `concepts::FloatingPoint T`. GCC 14 does not encode a +// template parameter's type-constraint in the mangled name; Clang 18+ does +// (`...ITkN3wtf8concepts13FloatingPointEdE...`). On an explicitly instantiated +// template that yields two different symbols: this library, built by GCC, +// exports the unconstrained name while a Clang consumer asks for the +// constrained one and fails to link. The requirement on T is enforced by a +// static_assert in the definition instead. +template Tensor generate_eigenvalues(const SymmetricMatrixSpec& spec, std::mt19937& gen); /** @brief Generates eigenvalues with element type `double`. diff --git a/cxx/include/tensorwrapper/generate/random_orthogonal_matrix.hpp b/cxx/include/tensorwrapper/generate/random_orthogonal_matrix.hpp index ecdb7a4e..28b95b2c 100644 --- a/cxx/include/tensorwrapper/generate/random_orthogonal_matrix.hpp +++ b/cxx/include/tensorwrapper/generate/random_orthogonal_matrix.hpp @@ -39,7 +39,14 @@ namespace tensorwrapper::generate { * * @throw std::invalid_argument if @p n is outside the allowed range. */ -template +// NB: `typename T`, not `concepts::FloatingPoint T`. GCC 14 does not encode a +// template parameter's type-constraint in the mangled name; Clang 18+ does +// (`...ITkN3wtf8concepts13FloatingPointEdE...`). On an explicitly instantiated +// template that yields two different symbols: this library, built by GCC, +// exports the unconstrained name while a Clang consumer asks for the +// constrained one and fails to link. The requirement on T is enforced by a +// static_assert in the definition instead. +template Tensor random_orthogonal_matrix(std::size_t n, std::mt19937& gen); /** @brief Creates a random orthogonal matrix with element type `double`. diff --git a/cxx/src/tensorwrapper/generate/add_noise.cpp b/cxx/src/tensorwrapper/generate/add_noise.cpp index f10e2cd4..b56583a4 100644 --- a/cxx/src/tensorwrapper/generate/add_noise.cpp +++ b/cxx/src/tensorwrapper/generate/add_noise.cpp @@ -56,13 +56,17 @@ Tensor add_noise_impl(const Tensor& matrix, double t, std::mt19937& gen) { } // namespace -template +template Tensor add_noise(const Tensor& matrix, double t, std::mt19937& gen) { + static_assert(concepts::FloatingPoint, + "T must be a floating point type"); return add_noise_impl(matrix, t, gen); } -template +template Tensor add_noise(const Tensor& matrix, double t, std::uint64_t seed) { + static_assert(concepts::FloatingPoint, + "T must be a floating point type"); auto gen = make_rng(seed); return add_noise(matrix, t, gen); } diff --git a/cxx/src/tensorwrapper/generate/generate_eigen_system.cpp b/cxx/src/tensorwrapper/generate/generate_eigen_system.cpp index d308aafa..e3730205 100644 --- a/cxx/src/tensorwrapper/generate/generate_eigen_system.cpp +++ b/cxx/src/tensorwrapper/generate/generate_eigen_system.cpp @@ -22,8 +22,10 @@ namespace tensorwrapper::generate { -template +template EigenSystem generate_eigen_system(const SymmetricMatrixSpec& spec) { + static_assert(concepts::FloatingPoint, + "T must be a floating point type"); require_valid_n(spec.n); auto gen = make_rng(spec.seed); const auto n = spec.n; diff --git a/cxx/src/tensorwrapper/generate/generate_eigenvalues.cpp b/cxx/src/tensorwrapper/generate/generate_eigenvalues.cpp index 0622df01..585d64f3 100644 --- a/cxx/src/tensorwrapper/generate/generate_eigenvalues.cpp +++ b/cxx/src/tensorwrapper/generate/generate_eigenvalues.cpp @@ -155,9 +155,11 @@ void sort_eigenvalues(std::vector& values) { } // namespace -template +template Tensor generate_eigenvalues(const SymmetricMatrixSpec& spec, std::mt19937& gen) { + static_assert(concepts::FloatingPoint, + "T must be a floating point type"); require_valid_n(spec.n); const auto n = spec.n; diff --git a/cxx/src/tensorwrapper/generate/random_orthogonal_matrix.cpp b/cxx/src/tensorwrapper/generate/random_orthogonal_matrix.cpp index 491d3ea1..650f1c97 100644 --- a/cxx/src/tensorwrapper/generate/random_orthogonal_matrix.cpp +++ b/cxx/src/tensorwrapper/generate/random_orthogonal_matrix.cpp @@ -40,8 +40,10 @@ Eigen::MatrixXd random_orthogonal_matrix_eigen(std::size_t n, } // namespace -template +template Tensor random_orthogonal_matrix(std::size_t n, std::mt19937& gen) { + static_assert(concepts::FloatingPoint, + "T must be a floating point type"); require_valid_n(n); const auto Q = random_orthogonal_matrix_eigen(n, gen);