17 #ifndef OPENKALMAN_COVARIANCEBASE3IMPL_HPP 18 #define OPENKALMAN_COVARIANCEBASE3IMPL_HPP 34 template<
typename Derived,
typename NestedMatrix>
45 using CholeskyNestedMatrix = std::conditional_t<
46 diagonal_matrix<NestedMatrix>,
47 typename MatrixTraits<std::decay_t<NestedMatrix>>::template DiagonalMatrixFrom<>,
48 std::conditional_t<triangular_matrix<NestedMatrix>,
49 typename MatrixTraits<std::decay_t<NestedMatrix>>::template SelfAdjointMatrixFrom<>,
50 typename MatrixTraits<std::decay_t<NestedMatrix>>::template TriangularAdapterFrom<>>>;
54 mutable CholeskyNestedMatrix cholesky_nested;
58 mutable int synch_direction;
65 auto& cholesky_nested_matrix() & {
return cholesky_nested; }
81 int synchronization_direction()
const {
return synch_direction; }
88 void synchronize_forward()
const &
96 void synchronize_forward()
const &&
98 cholesky_nested = to_covariance_nestable<CholeskyNestedMatrix>(std::move(*this).nested_object());
107 void mark_nested_matrix_changed()
const { synch_direction = 1; }
114 void mark_cholesky_nested_matrix_changed()
const { synch_direction = -1; }
121 void mark_synchronized()
const { synch_direction = 0; }
125 #ifdef __cpp_concepts 128 template<
typename T = NestedMatrix, std::enable_if_t<std::is_default_constructible_v<T>,
int> = 0>
131 :
Base {}, synch_direction {} {}
147 #ifdef __cpp_concepts 148 template<
typename Arg> requires (triangular_matrix<Arg> == triangular_matrix<NestedMatrix>) and
149 (not diagonal_matrix<Arg>)
151 template<
typename Arg, std::enable_if_t<(triangular_matrix<Arg> == triangular_matrix<NestedMatrix>) and
152 (not diagonal_matrix<Arg>),
int> = 0>
155 :
Base {std::forward<Arg>(arg)}, cholesky_nested {}, synch_direction {sd} {}
163 #ifdef __cpp_concepts 164 template<
typename Arg> requires (triangular_matrix<Arg> != triangular_matrix<NestedMatrix>) or diagonal_matrix<Arg>
166 template<
typename Arg, std::enable_if_t<(triangular_matrix<Arg> != triangular_matrix<NestedMatrix>) or
167 diagonal_matrix<Arg>,
int> = 0>
170 :
Base {}, cholesky_nested {std::forward<Arg>(arg)}, synch_direction {sd} {}
179 template<
typename N,
typename CN>
181 :
Base {std::forward<N>(n)}, cholesky_nested {std::forward<CN>(cn)}, synch_direction {sd} {}
189 if constexpr (not zero<NestedMatrix> and not identity_matrix<NestedMatrix>)
if (
this != &other)
192 if (synch_direction <= 0) cholesky_nested = other.cholesky_nested_matrix();
193 synch_direction = other.synch_direction;
202 if constexpr (not zero<NestedMatrix> and not identity_matrix<NestedMatrix>)
if (
this != &other)
205 if (synch_direction <= 0) cholesky_nested = std::move(other.cholesky_nested_matrix());
206 synch_direction = other.synch_direction;
216 #ifdef __cpp_concepts 217 template<covariance Arg> requires (not std::derived_from<std::decay_t<Arg>, CovarianceBase3Impl>)
219 template<
typename Arg, std::enable_if_t<covariance<Arg> and
220 (not std::is_base_of_v<CovarianceBase3Impl, std::decay_t<Arg>>),
int> = 0>
227 if constexpr (case1or2<Arg>)
231 not diagonal_matrix<Arg>)
234 mark_nested_matrix_changed();
238 cholesky_nested = to_covariance_nestable<CholeskyNestedMatrix>(std::forward<Arg>(arg));
239 mark_cholesky_nested_matrix_changed();
245 if (synch_direction >= 0)
249 if (synch_direction <= 0)
251 cholesky_nested = to_covariance_nestable<CholeskyNestedMatrix>(std::forward<Arg>(arg));
253 synch_direction = arg.synchronization_direction();
263 #ifdef __cpp_concepts 264 template<covariance_nestable Arg>
266 template<
typename Arg, std::enable_if_t<covariance_nestable<Arg>,
int> = 0>
270 if constexpr(not (zero<Arg> and zero<NestedMatrix>) and
271 not (identity_matrix<Arg> and identity_matrix<NestedMatrix>))
273 if constexpr(triangular_matrix<Arg> == triangular_matrix<NestedMatrix> and not diagonal_matrix<Arg>)
276 mark_nested_matrix_changed();
280 cholesky_nested = to_covariance_nestable<CholeskyNestedMatrix>(std::forward<Arg>(arg));
281 mark_cholesky_nested_matrix_changed();
296 if constexpr(writable_by_component<CholeskyNestedMatrix, 2>)
298 [
this] {
if (synch_direction > 0) synchronize_forward(); },
299 [
this] { mark_cholesky_nested_matrix_changed(); });
302 [
this] {
if (synch_direction > 0) synchronize_forward(); });
308 return ElementAccessor(cholesky_nested, i, j, [
this] {
if (synch_direction > 0) synchronize_forward(); });
319 if constexpr(writable_by_component<CholeskyNestedMatrix, 1>)
321 [
this] {
if (synch_direction > 0) synchronize_forward(); },
322 [
this] { mark_cholesky_nested_matrix_changed(); });
325 [
this] {
if (synch_direction > 0) synchronize_forward(); });
332 return ElementAccessor(cholesky_nested, i, [
this] {
if (synch_direction > 0) synchronize_forward(); });
339 void set_component(
const Scalar s,
const std::size_t i,
const std::size_t j)
341 if (synch_direction > 0) synchronize_forward();
343 mark_cholesky_nested_matrix_changed();
352 if (synch_direction > 0) synchronize_forward();
354 mark_cholesky_nested_matrix_changed();
362 #endif //OPENKALMAN_COVARIANCEBASE3IMPL_HPP Definition: ElementAccessor.hpp:34
typename nested_object_of< T >::type nested_object_of_t
Helper type for nested_object_of.
Definition: nested_object_of.hpp:66
auto && cholesky_nested_matrix() &&
Definition: CovarianceBase3Impl.hpp:71
constexpr NestedMatrix & nested_object() &
Get the nested object.
Definition: AdapterBase.hpp:97
Arg && set_component(Arg &&arg, const scalar_type_of_t< Arg > &s, const Indices &indices)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: set_component.hpp:51
typename scalar_type_of< T >::type scalar_type_of_t
helper template for scalar_type_of.
Definition: scalar_type_of.hpp:54
auto operator()(std::size_t i, std::size_t j)
Get or set element (i, j) of the covariance matrix.
Definition: CovarianceBase3Impl.hpp:294
auto operator[](std::size_t i)
Get or set element i of the covariance matrix.
Definition: CovarianceBase3Impl.hpp:317
Definition: AdapterBase.hpp:36
Definition: CovarianceBase3Impl.hpp:35
auto & operator=(CovarianceBase3Impl &&other) noexcept
Move assignment operator.
Definition: CovarianceBase3Impl.hpp:200
constexpr bool triangular_matrix
Specifies that a type is a triangular matrix (upper, lower, or diagonal).
Definition: triangular_matrix.hpp:37
constexpr bool zero
Specifies that a type is known at compile time to be a constant matrix of value zero.
Definition: zero.hpp:43
constexpr bool identity_matrix
Specifies that a type is an identity matrix.
Definition: identity_matrix.hpp:45
void set_component(const Scalar s, const std::size_t i, const std::size_t j)
Set an element of the cholesky nested matrix.
Definition: CovarianceBase3Impl.hpp:339
CovarianceBase3Impl()
Default constructor.
Definition: CovarianceBase3Impl.hpp:129
const auto && cholesky_nested_matrix() const &&
Definition: CovarianceBase3Impl.hpp:74
void set_component(const Scalar s, const std::size_t i)
Set an element of the cholesky nested matrix.
Definition: CovarianceBase3Impl.hpp:350
auto & operator=(Arg &&arg)
Assign from a covariance_nestable.
Definition: CovarianceBase3Impl.hpp:268
const auto & cholesky_nested_matrix() const &
Definition: CovarianceBase3Impl.hpp:68
auto & operator=(const CovarianceBase3Impl &other)
Copy assignment operator.
Definition: CovarianceBase3Impl.hpp:187
Definition: basics.hpp:48