forked from tlapack/tlapack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_mdspanplugin.cpp
82 lines (70 loc) · 3 KB
/
test_mdspanplugin.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
/// @file test/src/test_mdspanplugin.cpp
/// @author Weslley S Pereira, University of Colorado Denver, USA
/// @brief Tests for the mdspan plugin.
//
// 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"
#undef I // I is defined in complex.h and generates a conflict with templates
// in Catch2
#include <tlapack/plugins/mdspan.hpp>
TEST_CASE("STD layouts work as expected", "[plugins]")
{
using std::experimental::dextents;
using std::experimental::layout_left;
using std::experimental::layout_right;
using std::experimental::layout_stride;
using std::experimental::mdspan;
using tlapack::col;
using tlapack::cols;
using tlapack::Layout;
using tlapack::layout;
using tlapack::ncols;
using tlapack::nrows;
using tlapack::row;
using tlapack::rows;
using tlapack::slice;
using idx_t = std::size_t;
using range = std::pair<idx_t, idx_t>;
using my_dextents = dextents<idx_t, 2>;
mdspan<float, my_dextents, layout_left> A(nullptr, 11, 13);
mdspan<float, my_dextents, layout_right> B(nullptr, 7, 5);
mdspan<float, my_dextents, layout_stride> C(
nullptr, layout_stride::mapping<my_dextents>(
my_dextents{3, 4}, std::array<idx_t, 2>{1, 3}));
SECTION("mdspan layouts are correctly translated")
{
CHECK(layout<decltype(A)> == Layout::ColMajor);
CHECK(layout<decltype(B)> == Layout::RowMajor);
CHECK(layout<decltype(C)> == Layout::Unspecified);
}
SECTION("Slicing a mdspan sometimes turns the layout into Unspecified")
{
CHECK(layout<decltype(slice(A, range{0, 1}, range{0, 1}))> ==
Layout::Unspecified);
CHECK(layout<decltype(slice(B, range{0, 1}, range{0, 1}))> ==
Layout::Unspecified);
CHECK(layout<decltype(slice(C, range{0, 1}, range{0, 1}))> ==
Layout::Unspecified);
SECTION("layout_left (Column-major contiguous data)")
{
CHECK(layout<decltype(slice(A, range{0, nrows(A)}, range{0, 1}))> ==
Layout::Unspecified);
CHECK(layout<decltype(slice(A, range{0, nrows(A)}, 1))> ==
Layout::Strided);
CHECK(layout<decltype(slice(A, range{0, 1}, range{0, ncols(A)}))> ==
Layout::Unspecified);
CHECK(layout<decltype(slice(A, 1, range{0, ncols(A)}))> ==
Layout::Strided);
CHECK(layout<decltype(cols(A, range{0, 1}))> == Layout::ColMajor);
CHECK(layout<decltype(col(A, 1))> == Layout::Strided);
CHECK(layout<decltype(rows(A, range{0, 1}))> ==
Layout::Unspecified);
CHECK(layout<decltype(row(A, 1))> == Layout::Strided);
}
}
}