akreon-convex
Typed convex modeling, conic canonicalization, and primal-dual optimization in C++26.
Loading...
Searching...
No Matches
hyperplane.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 "convex_set.hpp"
9
10namespace convex {
11
13template <linalg::RnSpace Space>
15
17template <linalg::RnSpace Space>
19
21template <linalg::RnSpace Space>
25
31template <typename Meta, typename Child>
32struct Hyperplane : ConvexSet<Meta, Hyperplane<Meta, Child>, Child> {
35 using ConvexBase::N;
38
45 constexpr explicit Hyperplane(const PointT& a_in, T b_in,
46 const Child& child_in)
47 : ConvexBase(child_in), a(a_in), b(b_in) {}
48
58 constexpr bool contains_impl(const PointT& x, T tol) const {
59 return linalg::constexpr_abs(linalg::inner_product(a, x) - b) < tol;
60 }
61
67 constexpr bool is_well_formed() const {
68 if (linalg::all_zero(a)) return false;
69 return true;
70 }
71
84 template <linalg::SquareMatrix Mat>
85 requires(linalg::mat_cols_v<Mat> == N &&
86 std::same_as<linalg::matrix_scalar_t<Mat>, T>)
87 constexpr auto transform_impl(const affine::AffineMap<Mat>& map) const {
88 const auto [U_inv, event] = linalg::MatrixInverse<Mat>()(map.linear_part());
89 static_cast<void>(event);
90 const auto aT_U = transpose(as_col_vector(a)) * U_inv;
92 b + (aT_U * map.translation())(0),
93 std::get<0>(this->children));
94 }
95
101 template <typename Other>
102 constexpr bool is_equal_impl(const Other& other) const {
103 return other.self().a == a && other.self().b == b;
104 }
105
115 template <AtomType Type, conic::BuilderLike Builder>
116 constexpr auto canonicalize_set(const Builder& builder) const {
117 static_cast<void>(Type);
118 const auto child_builder =
119 std::get<0>(this->children)
120 .template canonicalize<AtomType::SET>(builder);
121 const auto child_coord = child_builder.coord_map;
122
123 static constexpr std::size_t ChildCodom =
124 linalg::mat_cols_v<decltype(child_coord.linear_part())>;
125 static_assert(ChildCodom == N,
126 "Convex set domain does not equal the child coordinate "
127 "linear map's codomain in size");
128
129 const auto eq_map = affine::AffineMap<linalg::RowVector<T, N>>(
130 linalg::as_row_vector(a), linalg::Vector<T, 1>{b})
132 const auto emission = conic::LocalEqualityEmission(eq_map);
133 return child_builder.realize(emission);
134 }
135
137 PointT a; //< n-dim vec of type T
138 T b; //< bias scalar of type T
139};
140
141template <typename Point, typename T, typename Child>
142Hyperplane(const Point&, const T&, const Child&)
145
146} // 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.
Atom-local equality emission bundle.
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
dom_type_t< Domain > T
Scalar field for the atom domain.
Definition atom.hpp:30
static constexpr std::size_t N
Domain dimension.
Definition atom.hpp:35
Atom metadata bundling domain, codomain, and curvature.
Domain wrapper with a static sign label.
forward declaration of convex set
forward declaration of hyperplane
constexpr bool contains_impl(const PointT &x, T tol) const
contains function to see if x lies in the hyerplane defined by a^T x = b
constexpr bool is_well_formed() const
is well formed checks to see if the hyperplane is valid
constexpr auto transform_impl(const affine::AffineMap< Mat > &map) const
transform implementation
constexpr auto canonicalize_set(const Builder &builder) const
canonicalize impl
PointT a
member var in hyperplane
constexpr Hyperplane(const PointT &a_in, T b_in, const Child &child_in)
CTOR for hyperplane.
constexpr bool is_equal_impl(const Other &other) const
is_equal implementation