Files
cppdraft_translate/cppdraft/linalg/conj.md
2025-10-25 03:02:53 +03:00

7.0 KiB
Raw Blame History

[linalg.conj]

29 Numerics library [numerics]

29.9 Basic linear algebra algorithms [linalg]

29.9.9 Conjugated in-place transformation [linalg.conj]

29.9.9.1 Introduction [linalg.conj.intro]

1

#

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.

29.9.9.2 Class template conjugated_accessor [linalg.conj.conjugatedaccessor]

1

#

The class template conjugated_accessor is an mdspan accessor policy which upon access produces conjugate elements.

It is part of the implementation ofconjugated ([linalg.conj.conjugated]).

namespace std::linalg {templateclass conjugated_accessor {public:using element_type = add_const_t<decltype(conj-if-needed(declvalNestedAccessor::element_type()))>; using reference = remove_const_t<element_type>; using data_handle_type = typename NestedAccessor::data_handle_type; using offset_policy = conjugated_accessorNestedAccessor::offset_policy; constexpr conjugated_accessor() = default; templateexplicit(!is_convertible_v<OtherNestedAccessor, NestedAccessor>>)constexpr conjugated_accessor(const conjugated_accessor& 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

#

Mandates:

element_type is valid and denotes a type,

is_copy_constructible_v is true,

is_reference_v<element_type> is false, and

NestedAccessor meets the accessor policy requirements ([mdspan.accessor.reqmts]).

🔗

constexpr conjugated_accessor(const NestedAccessor& acc);

3

#

Effects: Direct-non-list-initializesnested-accessor_ with acc.

🔗

template<class OtherNestedAccessor> explicit(!is_convertible_v<OtherNestedAccessor, NestedAccessor>>) constexpr conjugated_accessor(const conjugated_accessor<OtherNestedAccessor>& other);

4

#

Constraints: is_constructible_v<NestedAccessor, const OtherNestedAccessor&> is true.

5

#

Effects: Direct-non-list-initializes nested-accessor_ with other.nested_accessor().

🔗

constexpr reference access(data_handle_type p, size_t i) const;

6

#

Returns: conj-if-needed(NestedAccessor::element_type(nested-accessor_.access(p, i)))

🔗

constexpr typename offset_policy::data_handle_type offset(data_handle_type p, size_t i) const;

7

#

Returns: nested-accessor_.offset(p, i)

29.9.9.3 Function template conjugated [linalg.conj.conjugated]

🔗

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

#

Let A be

remove_cvref_t<decltype(a.accessor().nested_accessor())> if Accessor is a specialization of conjugated_accessor;

otherwise,Accessor if remove_cvref_t is an arithmetic type;

otherwise,conjugated_accessor if the expression conj(E) is valid for any subexpression E whose type is remove_cvref_t with overload resolution performed in a context that includes the declarationtemplate U conj(const U&) = delete;;

otherwise,Accessor.

2

#

Returns: Let MD be mdspan<typename A::element_type, Extents, Layout, A>.

MD(a.data_handle(), a.mapping(), a.accessor().nested_accessor()) if Accessor is a
specialization of conjugated_accessor;

otherwise,a, if is_same_v<A, Accessor> is true;

otherwise,MD(a.data_handle(), a.mapping(), conjugated_accessor(a.accessor())).

3

#

[Example 1: void test_conjugated_complex(mdspan<complex, 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]