Skip to content

Commit 7d63385

Browse files
committed
tests: small tweaks to linear algebra tests
1 parent 40a8e5f commit 7d63385

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

test/c++/nda_lapack.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include <algorithm>
1414
#include <complex>
15-
#include <numbers>
1615
#include <tuple>
1716
#include <type_traits>
1817

test/c++/nda_linear_algebra.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,20 +200,20 @@ void test_matmul() {
200200
}
201201

202202
template <typename T>
203-
constexpr auto test_matmul_layouts = []() {
203+
constexpr auto test_matmul_all_layouts = []() {
204204
test_matmul<T, nda::C_layout, nda::C_layout>();
205205
test_matmul<T, nda::C_layout, nda::F_layout>();
206206
test_matmul<T, nda::F_layout, nda::F_layout>();
207207
test_matmul<T, nda::F_layout, nda::C_layout>();
208208
};
209209

210-
TEST(NDA, LinearAlgebraMatmulGenericGemmBranch) { test_matmul_layouts<long>(); }
210+
TEST(NDA, LinearAlgebraMatmulGenericGemmBranch) { test_matmul_all_layouts<long>(); }
211211

212212
TEST(NDA, LinearAlgebraMatmulBLASBranch) {
213-
test_matmul_layouts<float>();
214-
test_matmul_layouts<std::complex<float>>();
215-
test_matmul_layouts<double>();
216-
test_matmul_layouts<std::complex<double>>();
213+
test_matmul_all_layouts<float>();
214+
test_matmul_all_layouts<std::complex<float>>();
215+
test_matmul_all_layouts<double>();
216+
test_matmul_all_layouts<std::complex<double>>();
217217
}
218218

219219
template <typename T>
@@ -278,6 +278,7 @@ void test_inv_and_det() {
278278
EXPECT_ARRAY_NEAR(Minv, Minv2, eps_close);
279279
EXPECT_COMPLEX_NEAR(nda::linalg::det(Minv2), 1.0 / detM, eps_close);
280280
Minv2 = nda::linalg::inv(Minv2);
281+
static_assert(std::is_same_v<nda::get_value_t<decltype(Minv2)>, T>);
281282
EXPECT_ARRAY_NEAR(M, Minv2, eps_close);
282283
EXPECT_COMPLEX_NEAR(nda::linalg::det(Minv2), detM, eps_close);
283284

@@ -314,6 +315,7 @@ void test_inv_and_det() {
314315
T detD = 16 * std::pow(fac, fp_t{4});
315316

316317
auto Dinv2 = nda::linalg::inv(D);
318+
static_assert(std::is_same_v<nda::get_value_t<decltype(Dinv2)>, T>);
317319
EXPECT_ARRAY_NEAR(Dinv, Dinv2, eps_close);
318320
EXPECT_COMPLEX_NEAR(nda::linalg::det(Dinv2), 1.0 / detD, eps_close);
319321
Dinv2 = nda::linalg::inv(Dinv2);
@@ -377,7 +379,8 @@ auto syhe_matrix(int n, double a = 1e-6, double b = 1.0) {
377379
}
378380

379381
// diagonal matrix containing the eigenvalues
380-
auto D = nda::eye<double>(n) * a + nda::diag(nda::vector<double>::rand(n)) * (b - a);
382+
using fp_type = nda::get_fp_t<T>;
383+
auto D = nda::eye<fp_type>(n) * a + nda::diag(nda::vector<fp_type>::rand(n)) * (b - a);
381384

382385
// return Q * D * Q^H (hermitian/symmetric)
383386
return matrix_t{Q * D * nda::dagger(Q)};
@@ -435,7 +438,7 @@ TEST(NDA, LinearAlgebraEighAndEigvalsh) {
435438
// Test the eigh and eigvalsh functions for generalized eigenvalue problems.
436439
template <typename T>
437440
void test_generalized_eigh_eigvalsh(int itype) {
438-
constexpr double eps_close = (std::is_same_v<T, float> || std::is_same_v<T, std::complex<float>>) ? 1.5e-5 : 1e-10;
441+
constexpr double eps_close = (std::is_same_v<T, float> || std::is_same_v<T, std::complex<float>>) ? 1e-4 : 1e-10;
439442
for (auto i : nda::range(1, 6)) {
440443
auto A = syhe_matrix<T>(i, -1, 1);
441444
auto B = syhe_matrix<T>(i, 1e-6, 1);

0 commit comments

Comments
 (0)