Files
2025-10-25 03:02:53 +03:00

162 lines
7.0 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[linalg.conj]
# 29 Numerics library [[numerics]](./#numerics)
## 29.9 Basic linear algebra algorithms [[linalg]](linalg#conj)
### 29.9.9 Conjugated in-place transformation [linalg.conj]
#### [29.9.9.1](#intro) Introduction [[linalg.conj.intro]](linalg.conj.intro)
[1](#intro-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12756)
The conjugated function takes an mdspan x,
and returns a new read-only mdspan y with the same domain as x,
whose elements are the complex conjugates
of the corresponding elements of x[.](#intro-1.sentence-1)
#### [29.9.9.2](#conjugatedaccessor) Class template conjugated_accessor [[linalg.conj.conjugatedaccessor]](linalg.conj.conjugatedaccessor)
[1](#conjugatedaccessor-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12765)
The class template conjugated_accessor is an mdspan accessor policy
which upon access produces conjugate elements[.](#conjugatedaccessor-1.sentence-1)
It is part of the implementation ofconjugated ([[linalg.conj.conjugated]](#conjugated "29.9.9.3Function template conjugated"))[.](#conjugatedaccessor-1.sentence-2)
namespace std::linalg {template<class NestedAccessor>class [conjugated_accessor](#lib:conjugated_accessor "29.9.9.2Class template conjugated_­accessor[linalg.conj.conjugatedaccessor]") {public:using element_type = add_const_t<decltype(*conj-if-needed*(declval<NestedAccessor::element_type>()))>; using reference = remove_const_t<element_type>; using data_handle_type = typename NestedAccessor::data_handle_type; using offset_policy = conjugated_accessor<NestedAccessor::offset_policy>; constexpr conjugated_accessor() = default; template<class OtherNestedAccessor>explicit(!is_convertible_v<OtherNestedAccessor, NestedAccessor>>)constexpr conjugated_accessor(const conjugated_accessor<OtherNestedAccessor>& other); constexpr reference access(data_handle_type p, size_t i) const; constexpr typename offset_policy::data_handle_type
offset(data_handle_type p, size_t i) const; constexpr const NestedAccessor& nested_accessor() const noexcept { return *nested-accessor_*; }private: NestedAccessor *nested-accessor_*{}; // *exposition only*};}
[2](#conjugatedaccessor-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12801)
*Mandates*:
- [(2.1)](#conjugatedaccessor-2.1)
element_type is valid and denotes a type,
- [(2.2)](#conjugatedaccessor-2.2)
is_copy_constructible_v<reference> is true,
- [(2.3)](#conjugatedaccessor-2.3)
is_reference_v<element_type> is false, and
- [(2.4)](#conjugatedaccessor-2.4)
NestedAccessor meets the accessor policy requirements ([[mdspan.accessor.reqmts]](mdspan.accessor.reqmts "23.7.3.5.2Requirements"))[.](#conjugatedaccessor-2.sentence-1)
[🔗](#lib:conjugated_accessor,constructor)
`constexpr conjugated_accessor(const NestedAccessor& acc);
`
[3](#conjugatedaccessor-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12820)
*Effects*: Direct-non-list-initializes*nested-accessor_* with acc[.](#conjugatedaccessor-3.sentence-1)
[🔗](#lib:conjugated_accessor,constructor_)
`template<class OtherNestedAccessor>
explicit(!is_convertible_v<OtherNestedAccessor, NestedAccessor>>)
constexpr conjugated_accessor(const conjugated_accessor<OtherNestedAccessor>& other);
`
[4](#conjugatedaccessor-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12834)
*Constraints*: is_constructible_v<NestedAccessor, const OtherNestedAccessor&> is true[.](#conjugatedaccessor-4.sentence-1)
[5](#conjugatedaccessor-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12839)
*Effects*: Direct-non-list-initializes *nested-accessor_* with other.nested_accessor()[.](#conjugatedaccessor-5.sentence-1)
[🔗](#lib:conjugated_accessor,access)
`constexpr reference access(data_handle_type p, size_t i) const;
`
[6](#conjugatedaccessor-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12851)
*Returns*: *conj-if-needed*(NestedAccessor::element_type(*nested-accessor_*.access(p, i)))
[🔗](#lib:conjugated_accessor,offset)
`constexpr typename offset_policy::data_handle_type offset(data_handle_type p, size_t i) const;
`
[7](#conjugatedaccessor-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12862)
*Returns*: *nested-accessor_*.offset(p, i)
#### [29.9.9.3](#conjugated) Function template conjugated [[linalg.conj.conjugated]](linalg.conj.conjugated)
[🔗](#conjugated-itemdecl:1)
` template<class ElementType, class Extents, class Layout, class Accessor>
constexpr auto [conjugated](#lib:conjugated "29.9.9.3Function template conjugated[linalg.conj.conjugated]")(mdspan<ElementType, Extents, Layout, Accessor> a);
`
[1](#conjugated-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12875)
Let A be
- [(1.1)](#conjugated-1.1)
remove_cvref_t<decltype(a.accessor().nested_accessor())> if Accessor is a specialization of conjugated_accessor;
- [(1.2)](#conjugated-1.2)
otherwise,Accessor if remove_cvref_t<ElementType> is an arithmetic type;
- [(1.3)](#conjugated-1.3)
otherwise,conjugated_accessor<Accessor> if the expression conj(E) is valid for any subexpression E whose type is remove_cvref_t<ElementType> with overload resolution performed in a context that includes the declarationtemplate<class U> U conj(const U&) = delete;;
- [(1.4)](#conjugated-1.4)
otherwise,Accessor[.](#conjugated-1.sentence-1)
[2](#conjugated-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12896)
*Returns*: Let MD be mdspan<typename A::element_type, Extents, Layout, A>[.](#conjugated-2.sentence-1)
- [(2.1)](#conjugated-2.1)
MD(a.data_handle(), a.mapping(), a.accessor().nested_accessor()) if Accessor is a
specialization of conjugated_accessor;
- [(2.2)](#conjugated-2.2)
otherwise,a, if is_same_v<A, Accessor> is true;
- [(2.3)](#conjugated-2.3)
otherwise,MD(a.data_handle(), a.mapping(), conjugated_accessor(a.accessor())).
[3](#conjugated-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12912)
[*Example [1](#conjugated-example-1)*: void test_conjugated_complex(mdspan<complex<double>, extents<int, 10>> a) {auto a_conj = conjugated(a); for (int i = 0; i < a.extent(0); ++i) { assert(a_conj[i] == conj(a[i]); }auto a_conj_conj = conjugated(a_conj); for (int i = 0; i < a.extent(0); ++i) { assert(a_conj_conj[i] == a[i]); }}void test_conjugated_real(mdspan<double, extents<int, 10>> a) {auto a_conj = conjugated(a); for (int i = 0; i < a.extent(0); ++i) { assert(a_conj[i] == a[i]); }auto a_conj_conj = conjugated(a_conj); for (int i = 0; i < a.extent(0); ++i) { assert(a_conj_conj[i] == a[i]); }} — *end example*]