Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
morphism_boundary.hpp
Go to the documentation of this file.
1
7#pragma once
8
10
11#include <cstddef>
12#include <string>
13#include <tuple>
14#include <type_traits>
15#include <utility>
16
17namespace uni20
18{
19
24template <Space... Spaces> class Domain {
25 public:
27 using tuple_type = std::tuple<Spaces...>;
28
31 template <std::size_t I> using space_type = std::tuple_element_t<I, tuple_type>;
32
35 explicit Domain(Spaces... spaces) : spaces_(std::move(spaces)...) {}
36
39 static constexpr auto size() noexcept -> std::size_t { return sizeof...(Spaces); }
40
43 static constexpr auto empty() noexcept -> bool { return sizeof...(Spaces) == 0; }
44
48 template <std::size_t I> constexpr auto space() const& noexcept -> space_type<I> const&
49 {
50 return std::get<I>(spaces_);
51 }
52
55 constexpr auto spaces() const& noexcept -> tuple_type const& { return spaces_; }
56
60 template <std::size_t I> void set_label(std::string label) { std::get<I>(spaces_).set_label(std::move(label)); }
61
65 auto operator==(Domain const& other) const -> bool = default;
66
67 private:
68 tuple_type spaces_;
69};
70
72template <class... Spaces> Domain(Spaces&&...) -> Domain<std::remove_cvref_t<Spaces>...>;
73
78template <Space... Spaces> class Codomain {
79 public:
81 using tuple_type = std::tuple<Spaces...>;
82
85 template <std::size_t I> using space_type = std::tuple_element_t<I, tuple_type>;
86
89 explicit Codomain(Spaces... spaces) : spaces_(std::move(spaces)...) {}
90
93 static constexpr auto size() noexcept -> std::size_t { return sizeof...(Spaces); }
94
97 static constexpr auto empty() noexcept -> bool { return sizeof...(Spaces) == 0; }
98
102 template <std::size_t I> constexpr auto space() const& noexcept -> space_type<I> const&
103 {
104 return std::get<I>(spaces_);
105 }
106
109 constexpr auto spaces() const& noexcept -> tuple_type const& { return spaces_; }
110
114 template <std::size_t I> void set_label(std::string label) { std::get<I>(spaces_).set_label(std::move(label)); }
115
119 auto operator==(Codomain const& other) const -> bool = default;
120
121 private:
122 tuple_type spaces_;
123};
124
126template <class... Spaces> Codomain(Spaces&&...) -> Codomain<std::remove_cvref_t<Spaces>...>;
127
128} // namespace uni20
Ordered codomain spaces of a tensor morphism.
Definition morphism_boundary.hpp:78
static constexpr auto size() noexcept -> std::size_t
Return the number of codomain factors.
Definition morphism_boundary.hpp:93
auto operator==(Codomain const &other) const -> bool=default
Compare ordered codomain spaces for exact equality.
void set_label(std::string label)
Replace one codomain leg label without changing its structure.
Definition morphism_boundary.hpp:114
Codomain(Spaces... spaces)
Construct a codomain from ordered space values.
Definition morphism_boundary.hpp:89
constexpr auto spaces() const &noexcept -> tuple_type const &
Return the ordered codomain-space tuple.
Definition morphism_boundary.hpp:109
constexpr auto space() const &noexcept -> space_type< I > const &
Return one codomain space by position.
Definition morphism_boundary.hpp:102
static constexpr auto empty() noexcept -> bool
Return whether the codomain is the tensor unit.
Definition morphism_boundary.hpp:97
std::tuple< Spaces... > tuple_type
Tuple containing the ordered codomain-space types.
Definition morphism_boundary.hpp:81
std::tuple_element_t< I, tuple_type > space_type
Type of one codomain space.
Definition morphism_boundary.hpp:85
Ordered domain spaces of a tensor morphism.
Definition morphism_boundary.hpp:24
auto operator==(Domain const &other) const -> bool=default
Compare ordered domain spaces for exact equality.
static constexpr auto size() noexcept -> std::size_t
Return the number of domain factors.
Definition morphism_boundary.hpp:39
static constexpr auto empty() noexcept -> bool
Return whether the domain is the tensor unit.
Definition morphism_boundary.hpp:43
constexpr auto space() const &noexcept -> space_type< I > const &
Return one domain space by position.
Definition morphism_boundary.hpp:48
Domain(Spaces... spaces)
Construct a domain from ordered space values.
Definition morphism_boundary.hpp:35
constexpr auto spaces() const &noexcept -> tuple_type const &
Return the ordered domain-space tuple.
Definition morphism_boundary.hpp:55
std::tuple_element_t< I, tuple_type > space_type
Type of one domain space.
Definition morphism_boundary.hpp:31
void set_label(std::string label)
Replace one domain leg label without changing its structure.
Definition morphism_boundary.hpp:60
std::tuple< Spaces... > tuple_type
Tuple containing the ordered domain-space types.
Definition morphism_boundary.hpp:27
Tensor-space value with a mutable semantic leg label.
Definition space.hpp:22
Definition qnum.hpp:403
Definition async/async.hpp:26
Defines the common tensor-space concepts.