136 lines
4.6 KiB
Markdown
136 lines
4.6 KiB
Markdown
[linalg.transp.transposed]
|
||
|
||
# 29 Numerics library [[numerics]](./#numerics)
|
||
|
||
## 29.9 Basic linear algebra algorithms [[linalg]](linalg#transp.transposed)
|
||
|
||
### 29.9.10 Transpose in-place transformation [[linalg.transp]](linalg.transp#transposed)
|
||
|
||
#### 29.9.10.4 Function template transposed [linalg.transp.transposed]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L13119)
|
||
|
||
The transposed function
|
||
takes a rank-2 mdspan representing a matrix, and
|
||
returns a new mdspan representing the input matrix's transpose[.](#1.sentence-1)
|
||
|
||
The input matrix's data are not modified, and
|
||
the returned mdspan accesses the input matrix's data in place[.](#1.sentence-2)
|
||
|
||
[ð](#lib:transposed)
|
||
|
||
` template<class ElementType, class Extents, class Layout, class Accessor>
|
||
constexpr auto transposed(mdspan<ElementType, Extents, Layout, Accessor> a);
|
||
`
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L13132)
|
||
|
||
*Mandates*: Extents::rank() == 2 is true[.](#2.sentence-1)
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L13136)
|
||
|
||
Let ReturnExtents be*transpose-extents-t*<Extents>[.](#3.sentence-1)
|
||
|
||
Let R bemdspan<ElementType, ReturnExtents, ReturnLayout, Accessor>,
|
||
where ReturnLayout is:
|
||
|
||
- [(3.1)](#3.1)
|
||
|
||
layout_right if Layout is layout_left;
|
||
|
||
- [(3.2)](#3.2)
|
||
|
||
otherwise, layout_left if Layout is layout_right;
|
||
|
||
- [(3.3)](#3.3)
|
||
|
||
otherwise, layout_right_padded<PaddingValue> if Layout is
|
||
layout_left_padded<PaddingValue> for some size_t value PaddingValue;
|
||
|
||
- [(3.4)](#3.4)
|
||
|
||
otherwise, layout_left_padded<PaddingValue> if Layout is
|
||
layout_right_padded<PaddingValue> for some size_t value PaddingValue;
|
||
|
||
- [(3.5)](#3.5)
|
||
|
||
otherwise, layout_stride if Layout is layout_stride;
|
||
|
||
- [(3.6)](#3.6)
|
||
|
||
otherwise,layout_blas_packed<OppositeTriangle, OppositeStorageOrder>,
|
||
if Layout is
|
||
layout_blas_packed<Triangle, StorageOrder> for some Triangle and StorageOrder, where
|
||
* [(3.6.1)](#3.6.1)
|
||
|
||
OppositeTriangle isconditional_t<is_same_v<Triangle, upper_triangle_t>,
|
||
lower_triangle_t, upper_triangle_t> and
|
||
|
||
* [(3.6.2)](#3.6.2)
|
||
|
||
OppositeStorageOrder isconditional_t<is_same_v<StorageOrder, column_major_t>, row_major_t, column_major_t>
|
||
|
||
- [(3.7)](#3.7)
|
||
|
||
otherwise, NestedLayout if Layout is layout_transpose<NestedLayout> for some NestedLayout;
|
||
|
||
- [(3.8)](#3.8)
|
||
|
||
otherwise, layout_transpose<Layout>[.](#3.sentence-2)
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L13185)
|
||
|
||
*Returns*: With ReturnMapping being
|
||
the type typename ReturnLayout::template mapping<ReturnExtents>:
|
||
|
||
- [(4.1)](#4.1)
|
||
|
||
if Layout is layout_left, layout_right, or
|
||
a specialization of layout_blas_packed,R(a.data_handle(), ReturnMapping(*transpose-extents*(a.mapping().extents())),
|
||
a.accessor())
|
||
|
||
- [(4.2)](#4.2)
|
||
|
||
otherwise,R(a.data_handle(), ReturnMapping(*transpose-extents*(a.mapping().extents()),
|
||
a.mapping().stride(1)), a.accessor()) if Layout is layout_left_padded<PaddingValue> for some size_t value PaddingValue;
|
||
|
||
- [(4.3)](#4.3)
|
||
|
||
otherwise,R(a.data_handle(), ReturnMapping(*transpose-extents*(a.mapping().extents()),
|
||
a.mapping().stride(0)), a.accessor()) if Layout is layout_right_padded<PaddingValue> for some size_t value PaddingValue;
|
||
|
||
- [(4.4)](#4.4)
|
||
|
||
otherwise, if Layout is layout_stride,R(a.data_handle(), ReturnMapping(*transpose-extents*(a.mapping().extents()),
|
||
array{a.mapping().stride(1), a.mapping().stride(0)}), a.accessor())
|
||
|
||
- [(4.5)](#4.5)
|
||
|
||
otherwise, if Layout is a specialization of layout_transpose,R(a.data_handle(), a.mapping().nested_mapping(), a.accessor())
|
||
|
||
- [(4.6)](#4.6)
|
||
|
||
otherwise,R(a.data_handle(), ReturnMapping(a.mapping()), a.accessor())
|
||
|
||
[5](#5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L13232)
|
||
|
||
[*Example [1](#example-1)*: void test_transposed(mdspan<double, extents<size_t, 3, 4>> a) {const auto num_rows = a.extent(0); const auto num_cols = a.extent(1); auto a_t = transposed(a);
|
||
assert(num_rows == a_t.extent(1));
|
||
assert(num_cols == a_t.extent(0));
|
||
assert(a.stride(0) == a_t.stride(1));
|
||
assert(a.stride(1) == a_t.stride(0)); for (size_t row = 0; row < num_rows; ++row) {for (size_t col = 0; col < num_rows; ++col) { assert(a[row, col] == a_t[col, row]); }}auto a_t_t = transposed(a_t);
|
||
assert(num_rows == a_t_t.extent(0));
|
||
assert(num_cols == a_t_t.extent(1));
|
||
assert(a.stride(0) == a_t_t.stride(0));
|
||
assert(a.stride(1) == a_t_t.stride(1)); for (size_t row = 0; row < num_rows; ++row) {for (size_t col = 0; col < num_rows; ++col) { assert(a[row, col] == a_t_t[row, col]); }}} â *end example*]
|