Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions cxx/include/tensorwrapper/generate/add_noise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ namespace tensorwrapper::generate {
*
* @throw std::invalid_argument if @p t is negative.
*/
template<concepts::FloatingPoint T>
// 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<typename T>
Tensor add_noise(const Tensor& matrix, double t, std::mt19937& gen);

/** @brief Overload of add_noise that creates its own RNG from @p seed.
Expand All @@ -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<concepts::FloatingPoint T>
// 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<typename T>
Tensor add_noise(const Tensor& matrix, double t, std::uint64_t seed = 42);

/** @brief Adds noise with element type `double`.
Expand Down
9 changes: 8 additions & 1 deletion cxx/include/tensorwrapper/generate/generate_eigen_system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ struct EigenSystem {
*
* @throw std::invalid_argument if @p spec.n is outside `[1, kMaxMatrixDim]`.
*/
template<concepts::FloatingPoint T>
// 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<typename T>
EigenSystem generate_eigen_system(const SymmetricMatrixSpec& spec);

/** @brief Generates an eigen-system with element type `double`.
Expand Down
9 changes: 8 additions & 1 deletion cxx/include/tensorwrapper/generate/generate_eigenvalues.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<concepts::FloatingPoint T>
// 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<typename T>
Tensor generate_eigenvalues(const SymmetricMatrixSpec& spec, std::mt19937& gen);

/** @brief Generates eigenvalues with element type `double`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ namespace tensorwrapper::generate {
*
* @throw std::invalid_argument if @p n is outside the allowed range.
*/
template<concepts::FloatingPoint T>
// 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<typename T>
Tensor random_orthogonal_matrix(std::size_t n, std::mt19937& gen);

/** @brief Creates a random orthogonal matrix with element type `double`.
Expand Down
8 changes: 6 additions & 2 deletions cxx/src/tensorwrapper/generate/add_noise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ Tensor add_noise_impl(const Tensor& matrix, double t, std::mt19937& gen) {

} // namespace

template<concepts::FloatingPoint T>
template<typename T>
Tensor add_noise(const Tensor& matrix, double t, std::mt19937& gen) {
static_assert(concepts::FloatingPoint<T>,
"T must be a floating point type");
return add_noise_impl<T>(matrix, t, gen);
}

template<concepts::FloatingPoint T>
template<typename T>
Tensor add_noise(const Tensor& matrix, double t, std::uint64_t seed) {
static_assert(concepts::FloatingPoint<T>,
"T must be a floating point type");
auto gen = make_rng(seed);
return add_noise<T>(matrix, t, gen);
}
Expand Down
4 changes: 3 additions & 1 deletion cxx/src/tensorwrapper/generate/generate_eigen_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

namespace tensorwrapper::generate {

template<concepts::FloatingPoint T>
template<typename T>
EigenSystem generate_eigen_system(const SymmetricMatrixSpec& spec) {
static_assert(concepts::FloatingPoint<T>,
"T must be a floating point type");
require_valid_n(spec.n);
auto gen = make_rng(spec.seed);
const auto n = spec.n;
Expand Down
4 changes: 3 additions & 1 deletion cxx/src/tensorwrapper/generate/generate_eigenvalues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ void sort_eigenvalues(std::vector<T>& values) {

} // namespace

template<concepts::FloatingPoint T>
template<typename T>
Tensor generate_eigenvalues(const SymmetricMatrixSpec& spec,
std::mt19937& gen) {
static_assert(concepts::FloatingPoint<T>,
"T must be a floating point type");
require_valid_n(spec.n);
const auto n = spec.n;

Expand Down
4 changes: 3 additions & 1 deletion cxx/src/tensorwrapper/generate/random_orthogonal_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ Eigen::MatrixXd random_orthogonal_matrix_eigen(std::size_t n,

} // namespace

template<concepts::FloatingPoint T>
template<typename T>
Tensor random_orthogonal_matrix(std::size_t n, std::mt19937& gen) {
static_assert(concepts::FloatingPoint<T>,
"T must be a floating point type");
require_valid_n(n);

const auto Q = random_orthogonal_matrix_eigen(n, gen);
Expand Down
Loading