akreon-convex
Typed convex modeling, conic canonicalization, and primal-dual optimization in C++26.
Loading...
Searching...
No Matches
intersection.hpp
Go to the documentation of this file.
1/*
2 * Copyright © 2025-2026 Akreon LLC
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#pragma once
7
8#include "cone_traits.hpp"
9#include "convex_traits.hpp"
10
11namespace convex {
12
22template <std::size_t idx = 0, typename Children, typename Builder, typename Fn>
23constexpr auto tuple_fold_cap(Children&& children, Builder&& builder, Fn&& fn) {
24 constexpr std::size_t N =
25 std::tuple_size_v<std::remove_reference_t<Children>>;
26 if constexpr (idx == N) return std::forward<Builder>(builder);
27 else {
28 auto&& child = std::get<idx>(std::forward<Children>(children));
29 auto new_builder =
30 std::forward<Fn>(fn)(child, std::forward<Builder>(builder));
31 return tuple_fold_cap<idx + 1>(std::forward<Children>(children),
32 std::move(new_builder),
33 std::forward<Fn>(fn));
34 }
35}
36
42template <typename Meta, typename... Cs>
43struct Intersection : Atom<Meta, Intersection<Meta, Cs...>, Cs...> {
45 using BaseT = Atom<Meta, Intersection<Meta, Cs...>, Cs...>;
48
54 constexpr explicit Intersection(const Cs... cs)
55 : BaseT(std::make_tuple(cs...)) {}
56
62 constexpr explicit Intersection(const std::tuple<Cs...>& cs) : BaseT(cs) {}
63
71 template <AtomType Type, conic::BuilderLike Builder>
72 constexpr auto canonicalize_impl(const Builder& builder) const {
73 static_assert(Type == AtomType::SET || Type == AtomType::CAP,
74 "Intersection is only supported on convex sets");
75 auto canonicalize_child = [&](const auto& child, const auto& builder_in) {
77 };
78 return tuple_fold_cap(this->children, builder, canonicalize_child);
79 }
80
88 constexpr bool contains(const PointT& x) const {
89 bool rv = true;
90 auto eval_child = [&](const auto& child) { rv &= child.contains(x); };
91 std::apply([&](const auto&... child) { (eval_child(child), ...); },
92 this->children);
93 return rv;
94 }
95};
96
97template <typename C0, typename... Cs>
98Intersection(const C0&, const Cs&...) -> Intersection<
101
102} // namespace convex
constexpr std::size_t dom_size_v
linalg::remove_cvref_t< T > atom_decay_t
normalize atom-facing types to a stable internal form.
constexpr auto tuple_fold_cap(Children &&children, Builder &&builder, Fn &&fn)
intersect over tuple
CRTP base for convex atoms.
Definition atom.hpp:22
ChildrenT children
Tuple of normalized child atoms.
Definition atom.hpp:240
dom_point_t< Domain > PointT
Point type accepted by the atom domain.
Definition atom.hpp:32
meta_dom_t< Meta > Domain
Atom input domain.
Definition atom.hpp:24
Atom metadata bundling domain, codomain, and curvature.
forward declaration of set intersection operator.
constexpr bool contains(const PointT &x) const
contains
constexpr auto canonicalize_impl(const Builder &builder) const
canonicalize impl
constexpr Intersection(const Cs... cs)
CTOR.
constexpr Intersection(const std::tuple< Cs... > &cs)
CTOR.