forked from tlapack/tlapack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_transpose.cpp
101 lines (82 loc) · 2.56 KB
/
test_transpose.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/// @file test_transpose.cpp
/// @author Thijs Steel, KU Leuven, Belgium
/// @brief Test transpose
//
// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
//
// This file is part of <T>LAPACK.
// <T>LAPACK is free software: you can redistribute it and/or modify it under
// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
// Test utilities and definitions (must come before <T>LAPACK headers)
#include "testutils.hpp"
// <T>LAPACK
#include <tlapack/lapack/transpose.hpp>
using namespace tlapack;
TEMPLATE_TEST_CASE("Conjugate Transpose gives correct result",
"[util]",
TLAPACK_TYPES_TO_TEST)
{
using matrix_t = TestType;
using T = type_t<matrix_t>;
using idx_t = size_type<matrix_t>;
// Functor
Create<matrix_t> new_matrix;
// MatrixMarket reader
MatrixMarket mm;
// Generate n
idx_t n = GENERATE(1, 2, 3, 5, 10);
// Generate m
idx_t m = GENERATE(1, 2, 3, 5, 10);
// Define the matrices
std::vector<T> A_;
auto A = new_matrix(A_, m, n);
std::vector<T> B_;
auto B = new_matrix(B_, n, m);
// Generate a random matrix in A
mm.random(A);
DYNAMIC_SECTION("m = " << m << " n = " << n)
{
TransposeOpts opts;
// Set nx to a small value so that the blocked algorithm gets tested
// even for small n and m;
opts.nx = 3;
conjtranspose(A, B, opts);
for (idx_t i = 0; i < m; ++i)
for (idx_t j = 0; j < n; ++j)
CHECK(B(j, i) == conj(A(i, j)));
}
}
TEMPLATE_TEST_CASE("Transpose gives correct result",
"[util]",
TLAPACK_TYPES_TO_TEST)
{
using matrix_t = TestType;
using T = type_t<matrix_t>;
using idx_t = size_type<matrix_t>;
// Functor
Create<matrix_t> new_matrix;
// MatrixMarket reader
MatrixMarket mm;
// Generate n
idx_t n = GENERATE(1, 2, 3, 5, 10);
// Generate m
idx_t m = GENERATE(1, 2, 3, 5, 10);
// Define the matrices
std::vector<T> A_;
auto A = new_matrix(A_, m, n);
std::vector<T> B_;
auto B = new_matrix(B_, n, m);
// Generate a random matrix in A
mm.random(A);
DYNAMIC_SECTION("m = " << m << " n = " << n)
{
TransposeOpts opts;
// Set nx to a small value so that the blocked algorithm gets tested
// even for small n and m;
opts.nx = 3;
transpose(A, B, opts);
for (idx_t i = 0; i < m; ++i)
for (idx_t j = 0; j < n; ++j)
CHECK(B(j, i) == A(i, j));
}
}