proxsuite 0.6.7
The Advanced Proximal Optimization Toolbox
Loading...
Searching...
No Matches
views.hpp
Go to the documentation of this file.
1//
2// Copyright (c) 2022 INRIA
3//
7#ifndef PROXSUITE_PROXQP_DENSE_VIEWS_HPP
8#define PROXSUITE_PROXQP_DENSE_VIEWS_HPP
9
12#include <cstring>
13#include <type_traits>
14#include <Eigen/Core>
15
16#define LDLT_CONCEPT(...) \
17 VEG_CONCEPT_MACRO(::proxsuite::proxqp::concepts, __VA_ARGS__)
18#define LDLT_CHECK_CONCEPT(...) \
19 VEG_CHECK_CONCEPT_MACRO(::proxqp::concepts, __VA_ARGS__)
20
21namespace proxsuite {
22namespace proxqp {
23
24using usize = decltype(sizeof(0));
25namespace detail {
26template<typename Fn>
27struct FnInfo;
28template<typename Ret_, typename... Args>
29struct FnInfo<auto(Args...)->Ret_>
30{
31 template<usize I>
32 using Arg = proxsuite::linalg::veg::ith<I, Args...>;
33 using Ret = Ret_;
34};
35} // namespace detail
36
37#define LDLT_IMPL_GET_PARAM(Fn, Idx) \
38 typename ::proxsuite::proxqp::detail::FnInfo< \
39 decltype Fn /* NOLINT */>::template Arg<(Idx)>,
40
41#define LDLT_IMPL_GET_PARAMS_0(NParams, ...) \
42 __VEG_PP_TUPLE_FOR_EACH(LDLT_IMPL_GET_PARAM, \
43 (__VA_ARGS__), \
44 __VEG_PP_MAKE_TUPLE(__VEG_IMPL_PP_DEC(NParams)))
45
46#define LDLT_IMPL_GET_PARAMS_1(NParams, ...)
47
48#define LDLT_IMPL_GET_PARAMS(NParams, ...) \
49 __VEG_PP_CAT2(LDLT_IMPL_GET_PARAMS_, __VEG_IMPL_PP_IS_1(NParams)) \
50 (NParams, __VA_ARGS__)
51
52#define LDLT_EXPLICIT_TPL_DEF(NParams, ...) \
53 template auto __VA_ARGS__( \
54 LDLT_IMPL_GET_PARAMS(NParams, __VA_ARGS__) \
55 typename ::proxsuite::proxqp::detail::FnInfo< \
56 decltype(__VA_ARGS__)>::template Arg<(NParams) - 1>) -> \
57 typename ::proxsuite::proxqp::detail::FnInfo<decltype(__VA_ARGS__)>::Ret
58#define LDLT_EXPLICIT_TPL_DECL(NParams, ...) \
59 extern LDLT_EXPLICIT_TPL_DEF(NParams, __VA_ARGS__)
60
67using f32 = float;
68using f64 = double;
69namespace detail {
70
71struct NoCopy
72{
73 NoCopy() = default;
74 ~NoCopy() = default;
75
76 NoCopy(NoCopy const&) = delete;
77 NoCopy(NoCopy&&) = delete;
78 auto operator=(NoCopy const&) -> NoCopy& = delete;
79 auto operator=(NoCopy&&) -> NoCopy& = delete;
80};
81
82template<typename Fn>
83struct Defer /* NOLINT */
84{
85 Fn fn;
87
88 VEG_INLINE ~Defer() noexcept(noexcept(VEG_FWD(fn)())) { VEG_FWD(fn)(); }
89};
90
91namespace nb {
92struct defer
93{
94 template<typename Fn>
95 VEG_INLINE constexpr auto operator()(Fn fn) const -> Defer<Fn>
96 {
97 return { VEG_FWD(fn), {} };
98 }
99};
100struct max2
101{
102 template<typename T>
103 VEG_INLINE constexpr auto operator()(T const& a, T const& b) const -> T const&
104 {
105 return a > b ? a : b;
106 }
107};
108struct min2
109{
110 template<typename T>
111 VEG_INLINE constexpr auto operator()(T a, T b) const -> T
112 {
113 return (a < b) ? a : b;
114 }
115};
116
117} // namespace nb
118
119template<typename T>
120constexpr auto
121min_list_impl(T init, T const* arr, usize n) noexcept -> T
122{
123 return (n == 0)
124 ? init
125 : nb::min2{}(init, detail::min_list_impl(*arr, arr + 1, n - 1));
126}
127template<typename T, usize N>
128constexpr auto
129cx_min_list(T const (&arr)[N]) noexcept -> T
130{
131 return detail::min_list_impl( //
132 arr[0],
133 arr + 1,
134 N - 1);
135}
136
137namespace nb {
139{
140 template<typename T>
141 VEG_INLINE auto operator()(std::initializer_list<T> list) const -> T
142 {
143 T const* data = list.begin();
144 isize len = isize(list.size());
145
146 T current_max = data[0];
147 for (isize i = 1; i < len; ++i) {
148 if (data[i] > current_max) {
149 current_max = data[i];
150 }
151 }
152 return current_max;
153 }
154};
155} // namespace nb
159VEG_NIEBLOID(max_list);
160
161template<typename T, bool = std::is_floating_point<T>::value>
163{
164 static void fn(T* dest, usize n)
165 {
166 for (usize i = 0; i < n; ++i) {
167 *dest = 0;
168 }
169 }
170};
171
172template<typename T>
173struct SetZeroImpl<T, true>
174{
175 static void fn(T* dest, usize n)
176 {
177 // TODO: assert bit representation is zero
178 std::memset(dest, 0, n * sizeof(T));
179 }
180};
181
182template<typename T>
183void
184set_zero(T* dest, usize n)
185{
186 SetZeroImpl<T>::fn(dest, n);
187}
188
189constexpr auto
190round_up(isize n, isize k) noexcept -> isize
191{
192 return (n + k - 1) / k * k;
193}
194constexpr auto
195uround_up(usize n, usize k) noexcept -> usize
196{
197 return (n + k - 1) / k * k;
198}
199
200inline auto
201bytes_to_prev_aligned(void* ptr, usize align) noexcept -> isize
202{
203 using UPtr = std::uintptr_t;
204
205 UPtr mask = align - 1;
206 UPtr iptr = UPtr(ptr);
207 UPtr aligned_ptr = iptr & ~mask;
208 return isize(aligned_ptr - iptr);
209}
210inline auto
211bytes_to_next_aligned(void* ptr, usize align) noexcept -> isize
212{
213 using UPtr = std::uintptr_t;
214
215 UPtr mask = align - 1;
216 UPtr iptr = UPtr(ptr);
217 UPtr aligned_ptr = (iptr + mask) & ~mask;
218 return isize(aligned_ptr - iptr);
219}
220
221inline auto
222next_aligned(void* ptr, usize align) noexcept -> void*
223{
224 using BytePtr = unsigned char*;
225 using VoidPtr = void*;
226 return VoidPtr(BytePtr(ptr) + detail::bytes_to_next_aligned(ptr, align));
227}
228inline auto
229prev_aligned(void* ptr, usize align) noexcept -> void*
230{
231 using BytePtr = unsigned char*;
232 using VoidPtr = void*;
233 return VoidPtr(BytePtr(ptr) + detail::bytes_to_prev_aligned(ptr, align));
234}
235
236} // namespace detail
237
238enum struct Layout : unsigned char
239{
240 colmajor = 0,
241 rowmajor = 1,
242};
243
246
247constexpr auto
249{
250 return Layout(1 - u32(l));
251}
252constexpr auto
254{
255 return l == colmajor ? Eigen::ColMajor : Eigen::RowMajor;
256}
257constexpr auto
259{
260 return (unsigned(l) & Eigen::RowMajorBit) == Eigen::RowMajor ? rowmajor
261 : colmajor;
262}
263
264static_assert(to_eigen_layout(from_eigen_layout(Eigen::ColMajor)) ==
265 Eigen::ColMajor,
266 ".");
267static_assert(to_eigen_layout(from_eigen_layout(Eigen::RowMajor)) ==
268 Eigen::RowMajor,
269 ".");
270
271namespace detail {
272template<Layout L>
274
275template<>
277{
278 template<typename T>
279 VEG_INLINE static constexpr auto offset(T* ptr,
280 isize row,
281 isize col,
282 isize outer_stride) noexcept -> T*
283 {
284 return ptr + (usize(row) + usize(col) * usize(outer_stride));
285 }
286
287 using NextRowStride = Eigen::Stride<0, 0>;
288 using NextColStride = Eigen::InnerStride<Eigen::Dynamic>;
289 VEG_INLINE static auto next_row_stride(isize outer_stride) noexcept
291 {
292 (void)outer_stride;
293 return NextRowStride{};
294 }
295 VEG_INLINE static auto next_col_stride(isize outer_stride) noexcept
297 {
298 return NextColStride /* NOLINT(modernize-return-braced-init-list) */ (
299 outer_stride);
300 }
301
302 template<typename T>
304 isize dim,
305 isize outer_stride)
306 {
307 (void)ptr, (void)dim, (void)outer_stride;
308 }
309};
310
311template<>
313{
314 template<typename T>
315 VEG_INLINE static constexpr auto offset(T* ptr,
316 isize row,
317 isize col,
318 isize outer_stride) noexcept -> T*
319 {
320 return ptr + (usize(col) + usize(row) * usize(outer_stride));
321 }
322
323 using NextColStride = Eigen::Stride<0, 0>;
324 using NextRowStride = Eigen::InnerStride<Eigen::Dynamic>;
325 VEG_INLINE static auto next_col_stride(isize outer_stride) noexcept
327 {
328 (void)outer_stride;
329 return NextColStride{};
330 }
331 VEG_INLINE static auto next_row_stride(isize outer_stride) noexcept
333 {
334 return NextRowStride /* NOLINT(modernize-return-braced-init-list) */ (
335 outer_stride);
336 }
337
338 template<typename T>
340 isize dim,
341 isize outer_stride)
342 {
343 Eigen::Map< //
344 Eigen::Matrix< //
345 T, //
346 Eigen::Dynamic, //
347 Eigen::Dynamic //
348 >, //
349 Eigen::Unaligned, //
350 Eigen::OuterStride<Eigen::Dynamic> //
351 >{
352 ptr,
353 dim,
354 dim,
355 Eigen::OuterStride<Eigen::Dynamic>(outer_stride),
356 }
357 .transposeInPlace();
358 }
359};
360} // namespace detail
361
362namespace detail {
363template<typename T>
364struct unlref
365{
366 using Type = T;
367};
368template<typename T>
369struct unlref<T&>
370{
371 using Type = T;
372};
373
374template<typename T>
375auto
376is_eigen_matrix_base_impl(Eigen::MatrixBase<T> const volatile*)
378auto
379is_eigen_matrix_base_impl(void const volatile*)
381
382template<typename T>
383auto
384is_eigen_owning_matrix_base_impl(Eigen::PlainObjectBase<T> const volatile*)
386auto
389
390template<typename... Ts>
391using Void = void;
392
393template<typename Mat, typename T>
394using DataExpr = decltype(static_cast<T*>(VEG_DECLVAL(Mat&).data()));
395
396template<typename Dummy,
397 typename Fallback,
398 template<typename...>
399 class F,
400 typename... Ts>
405
406template<typename Fallback, template<typename...> class F, typename... Ts>
407struct DetectedImpl<Void<F<Ts...>>, Fallback, F, Ts...>
409{
410 using Type = F<Ts...>;
411};
412
413template<typename Fallback, template<typename...> class F, typename... Ts>
414using Detected = typename DetectedImpl<void, Fallback, F, Ts...>::Type;
415
416template<typename T>
418 proxsuite::linalg::veg::meta::constant<isize, isize(T::ColsAtCompileTime)>;
419template<typename T>
421 proxsuite::linalg::veg::meta::constant<isize, isize(T::RowsAtCompileTime)>;
422template<typename T>
425 isize(T::InnerStrideAtCompileTime)>;
426template<typename T>
427using LayoutImpl = proxsuite::linalg::veg::meta::
428 constant<Layout, (bool(T::IsRowMajor) ? rowmajor : colmajor)>;
429
430template<typename T, Layout L>
431using EigenMatMap = Eigen::Map< //
432 Eigen::Matrix< //
433 T, //
434 Eigen::Dynamic, //
435 Eigen::Dynamic, //
436 (L == colmajor) //
437 ? Eigen::ColMajor //
438 : Eigen::RowMajor //
439 > const, //
440 Eigen::Unaligned, //
441 Eigen::OuterStride<Eigen::Dynamic> //
442 >;
443template<typename T, Layout L>
444using EigenMatMapMut = Eigen::Map< //
445 Eigen::Matrix< //
446 T, //
447 Eigen::Dynamic, //
448 Eigen::Dynamic, //
449 (L == colmajor) //
450 ? Eigen::ColMajor //
451 : Eigen::RowMajor //
452 >, //
453 Eigen::Unaligned, //
454 Eigen::OuterStride<Eigen::Dynamic> //
455 >;
456
457template<typename T, typename Stride>
458using EigenVecMap = Eigen::Map< //
459 Eigen::Matrix< //
460 T, //
461 Eigen::Dynamic, //
462 1 //
463 > const, //
464 Eigen::Unaligned, //
465 Stride //
466 >;
467template<typename T, typename Stride>
468using EigenVecMapMut = Eigen::Map< //
469 Eigen::Matrix< //
470 T, //
471 Eigen::Dynamic, //
472 1 //
473 >, //
474 Eigen::Unaligned, //
475 Stride //
476 >;
477
478template<typename T, Layout L>
480template<typename T, Layout L>
482template<typename T, Layout L>
484template<typename T, Layout L>
486
487template<typename T>
489template<typename T>
491
492} // namespace detail
493
494template<typename T>
496
497namespace eigen {
498template<typename T>
502 T>;
503template<typename T>
507 T>;
508template<typename T>
512 T>;
513template<typename T>
515 detail::Detected<proxsuite::linalg::veg::meta::
516 constant<Layout, Layout(static_cast<unsigned char>(-1))>,
518 T>;
519} // namespace eigen
520
521namespace concepts {
522VEG_DEF_CONCEPT(typename T, rvalue_ref, std::is_rvalue_reference<T>::value);
523VEG_DEF_CONCEPT(typename T, lvalue_ref, std::is_lvalue_reference<T>::value);
524VEG_DEF_CONCEPT((template<typename...> class F, typename... Ts),
525 detected,
527
528namespace aux {
529VEG_DEF_CONCEPT((typename Mat, typename T),
530 has_data_expr,
531 LDLT_CONCEPT(detected<detail::DataExpr, Mat, T>));
532
533VEG_DEF_CONCEPT((typename Mat),
534 matrix_base,
536 static_cast<Mat*>(nullptr)))::value);
537
538VEG_DEF_CONCEPT((typename Mat),
539 is_plain_object_base,
541 static_cast<Mat*>(nullptr)))::value);
542
543VEG_DEF_CONCEPT((typename Mat),
544 tmp_matrix,
545 (LDLT_CONCEPT(aux::is_plain_object_base<unref<Mat>>) &&
546 !LDLT_CONCEPT(lvalue_ref<Mat>)));
547} // namespace aux
548
549VEG_DEF_CONCEPT((typename Mat, typename T),
550 eigen_view,
551 (LDLT_CONCEPT(aux::matrix_base<unref<Mat>>) &&
552 LDLT_CONCEPT(aux::has_data_expr<Mat, T const>)));
553
554VEG_DEF_CONCEPT((typename Mat, typename T),
555 eigen_view_mut,
556 (LDLT_CONCEPT(aux::matrix_base<unref<Mat>>) &&
557 LDLT_CONCEPT(aux::has_data_expr<Mat, T>) &&
558 !LDLT_CONCEPT(aux::tmp_matrix<Mat>)));
559
560VEG_DEF_CONCEPT((typename Mat, typename T),
561 eigen_strided_vector_view,
562 (LDLT_CONCEPT(eigen_view<Mat, T>) &&
563 (eigen::CompTimeCols<unref<Mat>>::value == 1)));
564
565VEG_DEF_CONCEPT((typename Mat, typename T),
566 eigen_strided_vector_view_mut,
567 (LDLT_CONCEPT(eigen_view_mut<Mat, T>) &&
568 (eigen::CompTimeCols<unref<Mat>>::value == 1)));
569
570VEG_DEF_CONCEPT((typename Mat, typename T),
571 eigen_vector_view,
572 (LDLT_CONCEPT(eigen_strided_vector_view<Mat, T>) &&
573 (eigen::CompTimeInnerStride<unref<Mat>>::value == 1)));
574
575VEG_DEF_CONCEPT((typename Mat, typename T),
576 eigen_vector_view_mut,
577 (LDLT_CONCEPT(eigen_strided_vector_view_mut<Mat, T>) &&
578 (eigen::CompTimeInnerStride<unref<Mat>>::value == 1)));
579} // namespace concepts
580
581inline namespace tags {
582VEG_TAG(from_ptr_size, FromPtrSize);
583VEG_TAG(from_ptr_size_stride, FromPtrSizeStride);
584VEG_TAG(from_ptr_rows_cols_stride, FromPtrRowsColsStride);
585VEG_TAG(from_eigen, FromEigen);
586} // namespace tags
587
588template<typename T>
590{
591 T const* data;
592 isize dim;
593
595 VectorView(FromPtrSize /*tag*/, T const* _data, isize _dim) noexcept
596 : data(_data)
597 , dim(_dim)
598 {
599 }
600
601 VEG_TEMPLATE(typename Vec,
602 requires(LDLT_CONCEPT(eigen_vector_view<Vec, T>)),
604 (/*tag*/, FromEigen),
605 (vec, Vec const&)) noexcept
606 : data(vec.data())
607 , dim(vec.rows())
608 {
609 }
610
611 VEG_INLINE auto ptr(isize index) const noexcept -> T const*
612 {
613 return data + index;
614 }
615 VEG_INLINE auto operator()(isize index) const noexcept -> T const&
616 {
617 return *ptr(index);
618 }
619 VEG_INLINE auto segment(isize i, isize size) const noexcept -> VectorView
620 {
621 return {
622 from_ptr_size,
623 data + i,
624 size,
625 };
626 }
627 VEG_INLINE auto to_eigen() const -> detail::VecMap<T>
628 {
629 return detail::VecMap<T>(data, Eigen::Index(dim));
630 }
631};
632
633template<typename T>
635{
637 isize dim;
638
640 VectorViewMut(FromPtrSize /*tag*/, T* _data, isize _dim) noexcept
641 : data(_data)
642 , dim(_dim)
643 {
644 }
645
646 VEG_TEMPLATE(typename Vec,
647 requires(LDLT_CONCEPT(eigen_vector_view_mut<Vec, T>)),
649 (/*tag*/, FromEigen),
650 (vec, Vec&&)) noexcept
651 : data(vec.data())
652 , dim(vec.rows())
653 {
654 }
655
656 VEG_INLINE auto as_const() const noexcept -> VectorView<T>
657 {
658 return {
659 from_ptr_size,
660 data,
661 dim,
662 };
663 }
664 VEG_INLINE auto ptr(isize index) const noexcept -> T* { return data + index; }
665 VEG_INLINE auto operator()(isize index) const noexcept -> T&
666 {
667 return *ptr(index);
668 }
669 VEG_INLINE auto segment(isize i, isize size) const noexcept -> VectorViewMut
670 {
671 return {
672 from_ptr_size,
673 data + i,
674 size,
675 };
676 }
677 VEG_INLINE auto to_eigen() const -> detail::VecMapMut<T>
678 {
679 return detail::VecMapMut<T>(data, Eigen::Index(dim));
680 }
681};
682
683template<typename T>
685{
686 T const* data;
687 isize dim;
688 isize stride;
689
691 StridedVectorView(FromPtrSizeStride /*tag*/,
692 T const* _data,
693 isize _dim,
694 isize _stride) noexcept
695 : data(_data)
696 , dim(_dim)
697 , stride(_stride)
698 {
699 }
700
701 VEG_TEMPLATE(typename Vec,
702 requires(LDLT_CONCEPT(eigen_strided_vector_view<Vec, T>)),
704 (/*tag*/, FromEigen),
705 (vec, Vec const&)) noexcept
706 : data(vec.data())
707 , dim(vec.rows())
708 , stride(vec.innerStride())
709 {
710 }
711
712 VEG_INLINE auto ptr(isize index) const noexcept -> T const*
713 {
714 return data + stride * index;
715 }
716 VEG_INLINE auto operator()(isize index) const noexcept -> T const&
717 {
718 return *ptr(index);
719 }
720 VEG_INLINE auto segment(isize i,
721 isize size) const noexcept -> StridedVectorView
722 {
723 return {
724 from_ptr_size_stride,
725 data + stride * i,
726 size,
727 stride,
728 };
729 }
730 VEG_INLINE auto to_eigen() const
731 -> detail::EigenVecMap<T, Eigen::InnerStride<Eigen::Dynamic>>
732 {
734 data,
735 Eigen::Index(dim),
736 Eigen::Index(1),
737 Eigen::InnerStride<Eigen::Dynamic>(Eigen::Index(stride)));
738 }
739};
740
741template<typename T>
743{
745 isize dim;
746 isize stride;
747
749 StridedVectorViewMut(FromPtrSizeStride /*tag*/,
750 T* _data,
751 isize _dim,
752 isize _stride) noexcept
753 : data(_data)
754 , dim(_dim)
755 , stride(_stride)
756 {
757 }
758
759 VEG_TEMPLATE(typename Vec,
760 requires(LDLT_CONCEPT(eigen_strided_vector_view_mut<Vec, T>)),
762 (/*tag*/, FromEigen),
763 (vec, Vec&&)) noexcept
764 : data(vec.data())
765 , dim(vec.rows())
766 , stride(vec.innerStride())
767 {
768 }
769
770 VEG_INLINE auto as_const() const noexcept -> StridedVectorView<T>
771 {
772 return {
773 from_ptr_size_stride,
774 data,
775 dim,
776 stride,
777 };
778 }
779 VEG_INLINE auto ptr(isize index) const noexcept -> T*
780 {
781 return data + stride * index;
782 }
783 VEG_INLINE auto operator()(isize index) const noexcept -> T&
784 {
785 return *ptr(index);
786 }
787 VEG_INLINE auto segment(isize i,
788 isize size) const noexcept -> StridedVectorViewMut
789 {
790 return {
791 from_ptr_size_stride,
792 data + stride * i,
793 size,
794 stride,
795 };
796 }
797 VEG_INLINE auto to_eigen() const
798 -> detail::EigenVecMapMut<T, Eigen::InnerStride<Eigen::Dynamic>>
799 {
801 data,
802 Eigen::Index(dim),
803 Eigen::Index(1),
804 Eigen::InnerStride<Eigen::Dynamic>(Eigen::Index(stride)));
805 }
806};
807
808template<typename T, Layout L>
810{
811 T const* data;
812 isize rows;
813 isize cols;
815
816 VEG_INLINE MatrixView(FromPtrRowsColsStride /*tag*/,
817 T const* _data,
818 isize _rows,
819 isize _cols,
820 isize _outer_stride) noexcept
821 : data(_data)
822 , rows(_rows)
823 , cols(_cols)
824 , outer_stride(_outer_stride)
825 {
826 }
827
828 VEG_TEMPLATE(typename Mat,
829 requires(LDLT_CONCEPT(eigen_view<Mat, T>) &&
830 eigen::GetLayout<unref<Mat>>::value == L),
832 (/*tag*/, FromEigen),
833 (mat, Mat const&)) noexcept
834 : data(mat.data())
835 , rows(mat.rows())
836 , cols(mat.cols())
837 , outer_stride(mat.outerStride())
838 {
839 }
840
841 VEG_INLINE auto ptr(isize row, isize col) const noexcept -> T const*
842 {
844 }
845 VEG_INLINE auto operator()(isize row, isize col) const noexcept -> T const&
846 {
847 return *ptr(row, col);
848 }
849 VEG_INLINE auto block(isize row,
850 isize col,
851 isize nrows,
852 isize ncols) const noexcept -> MatrixView
853 {
854 return {
855 from_ptr_rows_cols_stride,
857 nrows,
858 ncols,
860 };
861 }
862
863private:
864 VEG_INLINE auto col_impl(
866 isize c) const noexcept -> VectorView<T>
867 {
868 return {
869 from_ptr_size,
870 data + c * outer_stride,
871 rows,
872 };
873 }
874 VEG_INLINE auto col_impl(
876 isize c) const noexcept -> StridedVectorView<T>
877 {
878 return {
879 from_ptr_size_stride,
880 data + c,
881 rows,
883 };
884 }
885
886public:
887 VEG_INLINE auto col(isize c) const noexcept
888 -> proxsuite::linalg::veg::meta::
890 {
892 }
893 VEG_INLINE auto row(isize r) const noexcept
894 -> proxsuite::linalg::veg::meta::
896 {
897 return trans().col(r);
898 }
899 VEG_INLINE auto trans() const noexcept
900 -> MatrixView<T, proxqp::flip_layout(L)>
901 {
902 return {
903 from_ptr_rows_cols_stride, data, cols, rows, outer_stride,
904 };
905 }
906 VEG_INLINE auto to_eigen() const noexcept -> detail::EigenMatMap<T, L>
907 {
909 data,
910 Eigen::Index(rows),
911 Eigen::Index(cols),
912 Eigen::OuterStride<Eigen::Dynamic>(Eigen::Index(outer_stride)));
913 }
914};
915
916template<typename T, Layout L>
918{
920 isize rows;
921 isize cols;
923
924 VEG_INLINE MatrixViewMut(FromPtrRowsColsStride /*tag*/,
925 T* _data,
926 isize _rows,
927 isize _cols,
928 isize _outer_stride) noexcept
929 : data(_data)
930 , rows(_rows)
931 , cols(_cols)
932 , outer_stride(_outer_stride)
933 {
934 }
935
936 VEG_TEMPLATE(typename Mat,
937 requires(LDLT_CONCEPT(eigen_view<Mat, T>) &&
938 eigen::GetLayout<unref<Mat>>::value == L),
940 (/*tag*/, FromEigen),
941 (mat, Mat&&)) noexcept
942 : data(mat.data())
943 , rows(mat.rows())
944 , cols(mat.cols())
945 , outer_stride(mat.outerStride())
946 {
947 }
948
949 VEG_INLINE auto ptr(isize row, isize col) const noexcept -> T*
950 {
952 }
953 VEG_INLINE auto operator()(isize row, isize col) const noexcept -> T&
954 {
955 return *ptr(row, col);
956 }
957 VEG_INLINE auto block(isize row,
958 isize col,
959 isize nrows,
960 isize ncols) const noexcept -> MatrixViewMut
961 {
962 return {
963 from_ptr_rows_cols_stride,
965 nrows,
966 ncols,
968 };
969 }
970
971private:
972 VEG_INLINE auto col_impl(
974 isize c) const noexcept -> VectorViewMut<T>
975 {
976 return {
977 from_ptr_size,
978 data + c * outer_stride,
979 rows,
980 };
981 }
982 VEG_INLINE auto col_impl(
984 isize c) const noexcept -> StridedVectorViewMut<T>
985 {
986 return {
987 from_ptr_size_stride,
988 data + c,
989 rows,
991 };
992 }
993
994public:
995 VEG_INLINE auto col(isize c) const noexcept
996 -> proxsuite::linalg::veg::meta::
998 {
1000 }
1001 VEG_INLINE auto row(isize r) const noexcept
1002 -> proxsuite::linalg::veg::meta::
1004 {
1005 return trans().col(r);
1006 }
1007 VEG_INLINE auto trans() const noexcept
1009 {
1010 return {
1011 from_ptr_rows_cols_stride, data, cols, rows, outer_stride,
1012 };
1013 }
1014 VEG_INLINE auto to_eigen() const noexcept -> detail::EigenMatMapMut<T, L>
1015 {
1017 data,
1018 Eigen::Index(rows),
1019 Eigen::Index(cols),
1020 Eigen::OuterStride<Eigen::Dynamic>(Eigen::Index(outer_stride)));
1021 }
1022 VEG_INLINE auto as_const() const noexcept -> MatrixView<T, L>
1023 {
1024 return {
1025 from_ptr_rows_cols_stride, data, rows, cols, outer_stride,
1026 };
1027 }
1028};
1029
1030template<typename T>
1032{
1033private:
1035
1036public:
1037 explicit LdltView(MatrixView<T, colmajor> ld) noexcept
1038 : ld(ld)
1039 {
1040 VEG_DEBUG_ASSERT(ld.rows == ld.cols);
1041 }
1042
1043 VEG_INLINE auto l() const noexcept -> MatrixView<T, colmajor> { return ld; }
1044 VEG_INLINE auto d() const noexcept -> StridedVectorView<T>
1045 {
1046 return { from_ptr_size_stride, ld.data, ld.rows, ld.outer_stride + 1 };
1047 }
1048
1049 VEG_INLINE auto head(isize k) const -> LdltView
1050 {
1051 return LdltView{ ld.block(0, 0, k, k) };
1052 }
1053 VEG_INLINE auto tail(isize k) const -> LdltView
1054 {
1055 isize n = ld.rows;
1056 return LdltView{ ld.block(n - k, n - k, k, k) };
1057 }
1058};
1059template<typename T>
1061{
1062private:
1064
1065public:
1067 : ld(ld)
1068 {
1069 VEG_DEBUG_ASSERT(ld.rows == ld.cols);
1070 }
1071
1072 VEG_INLINE auto l() const noexcept -> MatrixView<T, colmajor>
1073 {
1074 return ld.as_const();
1075 }
1076 VEG_INLINE auto l_mut() const noexcept -> MatrixViewMut<T, colmajor>
1077 {
1078 return ld;
1079 }
1080 VEG_INLINE auto d() const noexcept -> StridedVectorView<T>
1081 {
1082 return { from_ptr_size_stride, ld.data, ld.rows, ld.outer_stride + 1 };
1083 }
1084 VEG_INLINE auto d_mut() const noexcept -> StridedVectorViewMut<T>
1085 {
1086 return { from_ptr_size_stride, ld.data, ld.rows, ld.outer_stride + 1 };
1087 }
1088
1089 VEG_INLINE auto as_const() const noexcept -> LdltView<T>
1090 {
1091 return LdltView<T>{ ld.as_const() };
1092 }
1093
1094 VEG_INLINE auto head(isize k) const -> LdltViewMut
1095 {
1096 return LdltViewMut{ ld.block(0, 0, k, k) };
1097 }
1098 VEG_INLINE auto tail(isize k) const -> LdltViewMut
1099 {
1100 isize n = ld.rows;
1101 return LdltViewMut{ ld.block(n - k, n - k, k, k) };
1102 }
1103};
1104
1105namespace detail {
1106template<typename T>
1107void
1111 T factor)
1112{
1113
1114 if ((dst.cols == 0) || (dst.rows == 0) || (lhs.cols == 0)) {
1115 return;
1116 }
1117
1118#if !EIGEN_VERSION_AT_LEAST(3, 3, 8)
1119#define LAZY_PRODUCT(a, b) a.lazyProduct(b)
1120#else
1121#define LAZY_PRODUCT(a, b) a.operator*(b)
1122#endif
1123
1124 if (dst.cols == 1 && dst.rows == 1) {
1125 // dot
1126 auto rhs_col = rhs.col(0);
1127 auto lhs_row = lhs.row(0);
1128 auto lhs_as_col = lhs.col(0);
1129 lhs_as_col.dim = lhs_row.dim;
1130 if (lhs_row.stride == 1) {
1131 dst(0, 0) += factor * lhs_as_col.to_eigen().dot(rhs_col.to_eigen());
1132 } else {
1133 dst(0, 0) += factor * lhs_row.to_eigen().dot(rhs_col.to_eigen());
1134 }
1135 } else if (dst.cols == 1) {
1136 // gemv
1137 auto rhs_col = rhs.col(0);
1138 auto dst_col = dst.col(0);
1139 dst_col.to_eigen().noalias().operator+=(
1140 factor * LAZY_PRODUCT(lhs.to_eigen(), rhs_col.to_eigen()));
1141 }
1142
1143#if !EIGEN_VERSION_AT_LEAST(3, 3, 8)
1144 else if ((dst.rows < 20) && (dst.cols < 20) && (rhs.rows < 20)) {
1145 // gemm
1146 // workaround for eigen 3.3.7 bug:
1147 // https://gitlab.com/libeigen/eigen/-/issues/1562
1148 using Stride = Eigen::OuterStride<Eigen::Dynamic>;
1149 using Mat =
1150 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor, 20, 20>;
1151 using MapMut = Eigen::Map<Mat, Eigen::Unaligned, Stride>;
1152 using Map = Eigen::Map<Mat const, Eigen::Unaligned, Stride>;
1153
1154 MapMut(dst.data, dst.rows, dst.cols, Stride(dst.outer_stride))
1155 .noalias()
1156 .operator+=(
1157 factor *
1159 Map(lhs.data, lhs.rows, lhs.cols, Stride(lhs.outer_stride)),
1160 Map(rhs.data, rhs.rows, rhs.cols, Stride(rhs.outer_stride))));
1161 }
1162#endif
1163
1164 else {
1165 // gemm
1166 dst.to_eigen().noalias().operator+=(
1167 factor * LAZY_PRODUCT(lhs.to_eigen(), rhs.to_eigen()));
1168 }
1169
1170#undef LAZY_PRODUCT
1171}
1172
1173template<typename T>
1174void
1177 VectorView<T> rhs,
1178 T factor)
1179{
1180 detail::noalias_mul_add<T>(
1181 {
1182 from_ptr_rows_cols_stride,
1183 dst.data,
1184 dst.dim,
1185 1,
1186 0,
1187 },
1188 lhs,
1189 {
1190 from_ptr_rows_cols_stride,
1191 rhs.data,
1192 rhs.dim,
1193 1,
1194 0,
1195 },
1196 VEG_FWD(factor));
1197}
1198
1199template<typename T>
1200auto
1202{
1203 auto out = T(0);
1204 detail::noalias_mul_add<T>(
1205 {
1206 from_ptr_rows_cols_stride,
1207 std::addressof(out),
1208 1,
1209 1,
1210 0,
1211 },
1212 {
1213 from_ptr_rows_cols_stride,
1214 lhs.data,
1215 1,
1216 lhs.dim,
1217 lhs.stride,
1218 },
1219 {
1220 from_ptr_rows_cols_stride,
1221 rhs.data,
1222 rhs.dim,
1223 1,
1224 0,
1225 },
1226 1);
1227 return out;
1228}
1229template<typename T>
1230void
1234{
1235 out.to_eigen() = lhs.to_eigen().cwiseProduct(rhs.to_eigen());
1236}
1237template<typename T>
1238void
1240{
1241 out.to_eigen() = in.to_eigen().operator*(factor);
1242}
1243
1244template<typename T>
1245void
1248{
1249 if (rhs.cols == 1) {
1250 tr.to_eigen()
1251 .transpose()
1252 .template triangularView<Eigen::UnitUpper>()
1253 .template solveInPlace<Eigen::OnTheRight>(rhs.col(0).to_eigen());
1254 } else {
1255 tr.to_eigen()
1256 .transpose()
1257 .template triangularView<Eigen::UnitUpper>()
1258 .template solveInPlace<Eigen::OnTheRight>(rhs.to_eigen());
1259 }
1260}
1261
1262template<typename T>
1263void
1267{
1268 if (out.cols == 1) {
1269 out.col(0).to_eigen() =
1270 in.col(0).to_eigen().operator*(d.to_eigen().asDiagonal().inverse());
1271 } else {
1272 out.to_eigen() =
1273 in.to_eigen().operator*(d.to_eigen().asDiagonal().inverse());
1274 }
1275}
1276template<typename T>
1277void
1281{
1282 if (out.cols == 1) {
1283 out.col(0).to_eigen() =
1284 in.col(0).to_eigen().operator*(d.to_eigen().asDiagonal());
1285 } else {
1286 out.to_eigen() = in.to_eigen().operator*(d.to_eigen().asDiagonal());
1287 }
1288}
1289
1290template<typename T>
1291void
1295{
1296 if (lhs.cols == 1) {
1297 out.to_eigen().template triangularView<Eigen::Lower>().operator-=(
1298 lhs.col(0).to_eigen().operator*(
1299 Eigen::Map<Eigen::Matrix<T, 1, Eigen::Dynamic> const>(
1300 rhs.data, 1, rhs.cols)));
1301 } else {
1302 out.to_eigen().template triangularView<Eigen::Lower>().operator-=(
1303 lhs.to_eigen().operator*(rhs.to_eigen()));
1304 }
1305}
1306
1307} // namespace detail
1308} // namespace proxqp
1309} // namespace proxsuite
1310
1311namespace proxsuite {
1312namespace proxqp {
1313
1314namespace dense {
1315
1317{
1322 auto operator=(EigenAllowAlloc const&) -> EigenAllowAlloc& = delete;
1323
1324#if defined(EIGEN_RUNTIME_NO_MALLOC)
1325 EigenAllowAlloc() noexcept
1326 : alloc_was_allowed(Eigen::internal::is_malloc_allowed())
1327 {
1328 Eigen::internal::set_is_malloc_allowed(true);
1329 }
1330 ~EigenAllowAlloc() noexcept
1331 {
1332 Eigen::internal::set_is_malloc_allowed(alloc_was_allowed);
1333 }
1334#else
1335 EigenAllowAlloc() = default;
1336#endif
1337};
1338
1339template<typename T>
1353
1354template<typename Scalar>
1371
1372template<typename T>
1374{
1375 static constexpr Layout layout = rowmajor;
1376
1379
1384
1385 VEG_INLINE constexpr auto as_const() const noexcept -> QpView<T>
1386 {
1387 return {
1388 H.as_const(), g.as_const(), A.as_const(),
1389 b.as_const(), C.as_const(), d.as_const(),
1390 };
1391 }
1392};
1393
1394template<typename Scalar>
1418
1419namespace nb {
1420struct pow
1421{
1422 template<typename T>
1423 auto operator()(T x, T y) const -> T
1424 {
1425 using std::pow;
1426 return pow(x, y);
1427 }
1428};
1430{
1431 template<typename D>
1432 auto operator()(Eigen::MatrixBase<D> const& mat) const -> typename D::Scalar
1433 {
1434 if (mat.rows() == 0 || mat.cols() == 0) {
1435 return typename D::Scalar(0);
1436 } else {
1437 return mat.template lpNorm<Eigen::Infinity>();
1438 }
1439 }
1440};
1441struct sqrt
1442{
1443 template<typename T>
1444 auto operator()(T x) const -> T
1445 {
1446 using std::sqrt;
1447 return sqrt(x);
1448 }
1449};
1450struct fabs
1451{
1452 template<typename T>
1453 auto operator()(T x) const -> T
1454 {
1455 using std::fabs;
1456 return fabs(x);
1457 }
1458};
1459} // namespace nb
1463VEG_NIEBLOID(infty_norm);
1464} // namespace dense
1465} // namespace proxqp
1466} // namespace proxsuite
1467
1468#endif /* end of include guard PROXSUITE_PROXQP_DENSE_VIEWS_HPP */
#define VEG_DEBUG_ASSERT(...)
Definition assert.hpp:38
#define LAZY_PRODUCT(a, b)
#define LDLT_CONCEPT(...)
Definition views.hpp:16
#define VEG_TAG(Name, Type)
Definition macros.hpp:550
#define VEG_NIEBLOID(Name)
Definition macros.hpp:545
#define VEG_INLINE
Definition macros.hpp:118
#define VEG_FWD(X)
Definition macros.hpp:569
#define VEG_DECLVAL(...)
Definition macros.hpp:131
#define VEG_DEF_CONCEPT(Tpl, Name,...)
Definition macros.hpp:321
bool_constant< false > false_type
Definition macros.hpp:903
bool_constant< true > true_type
Definition macros.hpp:902
typename _detail::pack_ith_elem< I >::template Type< Ts... > ith
std::uint64_t u64
Definition typedefs.hpp:46
std::uint32_t u32
Definition typedefs.hpp:48
_detail::_meta::make_signed< usize >::Type isize
Definition typedefs.hpp:43
proxsuite::linalg::veg::meta::constant< isize, isize(T::RowsAtCompileTime)> CompTimeRowsImpl
Definition views.hpp:420
auto prev_aligned(void *ptr, usize align) noexcept -> void *
Definition views.hpp:229
void apply_diag_on_right(MatrixViewMut< T, colmajor > out, StridedVectorView< T > d, MatrixView< T, colmajor > in)
Definition views.hpp:1278
EigenVecMapMut< T, typename ElementAccess< L >::NextRowStride > ColToVecMut
Definition views.hpp:483
constexpr auto cx_min_list(T const (&arr)[N]) noexcept -> T
Definition views.hpp:129
auto is_eigen_matrix_base_impl(Eigen::MatrixBase< T > const volatile *) -> proxsuite::linalg::veg::meta::true_type
auto is_eigen_owning_matrix_base_impl(Eigen::PlainObjectBase< T > const volatile *) -> proxsuite::linalg::veg::meta::true_type
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic,(L==colmajor) ? Eigen::ColMajor :Eigen::RowMajor > const, Eigen::Unaligned, Eigen::OuterStride< Eigen::Dynamic > > EigenMatMap
Definition views.hpp:431
EigenVecMap< T, Eigen::Stride< 0, 0 > > VecMap
Definition views.hpp:488
auto bytes_to_prev_aligned(void *ptr, usize align) noexcept -> isize
Definition views.hpp:201
auto next_aligned(void *ptr, usize align) noexcept -> void *
Definition views.hpp:222
EigenVecMapMut< T, Eigen::Stride< 0, 0 > > VecMapMut
Definition views.hpp:490
void noalias_mul_add(MatrixViewMut< T, colmajor > dst, MatrixView< T, colmajor > lhs, MatrixView< T, colmajor > rhs, T factor)
Definition views.hpp:1108
auto bytes_to_next_aligned(void *ptr, usize align) noexcept -> isize
Definition views.hpp:211
constexpr auto min_list_impl(T init, T const *arr, usize n) noexcept -> T
Definition views.hpp:121
EigenVecMap< T, typename ElementAccess< L >::NextRowStride > ColToVec
Definition views.hpp:479
auto dot(StridedVectorView< T > lhs, VectorView< T > rhs) -> T
Definition views.hpp:1201
proxsuite::linalg::veg::meta::constant< isize, isize(T::ColsAtCompileTime)> CompTimeColsImpl
Definition views.hpp:417
decltype(static_cast< T * >(VEG_DECLVAL(Mat &).data())) DataExpr
Definition views.hpp:394
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic,(L==colmajor) ? Eigen::ColMajor :Eigen::RowMajor >, Eigen::Unaligned, Eigen::OuterStride< Eigen::Dynamic > > EigenMatMapMut
Definition views.hpp:444
void set_zero(T *dest, usize n)
Definition views.hpp:184
void apply_diag_inv_on_right(MatrixViewMut< T, colmajor > out, StridedVectorView< T > d, MatrixView< T, colmajor > in)
Definition views.hpp:1264
proxsuite::linalg::veg::meta::constant< isize, isize(T::InnerStrideAtCompileTime)> CompTimeInnerStrideImpl
Definition views.hpp:423
EigenVecMapMut< T, typename ElementAccess< L >::NextColStride > RowToVecMut
Definition views.hpp:485
EigenVecMap< T, typename ElementAccess< L >::NextColStride > RowToVec
Definition views.hpp:481
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, 1 >, Eigen::Unaligned, Stride > EigenVecMapMut
Definition views.hpp:468
void assign_scalar_prod(VectorViewMut< T > out, T factor, VectorView< T > in)
Definition views.hpp:1239
proxsuite::linalg::veg::meta:: constant< Layout,(bool(T::IsRowMajor) ? rowmajor :colmajor)> LayoutImpl
Definition views.hpp:427
void trans_tr_unit_up_solve_in_place_on_right(MatrixView< T, colmajor > tr, MatrixViewMut< T, colmajor > rhs)
Definition views.hpp:1246
constexpr auto round_up(isize n, isize k) noexcept -> isize
Definition views.hpp:190
void assign_cwise_prod(VectorViewMut< T > out, StridedVectorView< T > lhs, StridedVectorView< T > rhs)
Definition views.hpp:1231
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, 1 > const, Eigen::Unaligned, Stride > EigenVecMap
Definition views.hpp:458
void noalias_mul_add_vec(VectorViewMut< T > dst, MatrixView< T, colmajor > lhs, VectorView< T > rhs, T factor)
Definition views.hpp:1175
void noalias_mul_sub_tr_lo(MatrixViewMut< T, colmajor > out, MatrixView< T, colmajor > lhs, MatrixView< T, rowmajor > rhs)
Definition views.hpp:1292
typename DetectedImpl< void, Fallback, F, Ts... >::Type Detected
Definition views.hpp:414
constexpr auto uround_up(usize n, usize k) noexcept -> usize
Definition views.hpp:195
detail::Detected< proxsuite::linalg::veg::meta::constant< isize, 0 >, detail::CompTimeColsImpl, T > CompTimeCols
Definition views.hpp:499
detail::Detected< proxsuite::linalg::veg::meta::constant< isize, 0 >, detail::CompTimeInnerStrideImpl, T > CompTimeInnerStride
Definition views.hpp:509
detail::Detected< proxsuite::linalg::veg::meta::constant< isize, 0 >, detail::CompTimeRowsImpl, T > CompTimeRows
Definition views.hpp:504
detail::Detected< proxsuite::linalg::veg::meta:: constant< Layout, Layout(static_cast< unsigned char >(-1))>, detail::LayoutImpl, T > GetLayout
Definition views.hpp:514
constexpr auto flip_layout(Layout l) noexcept -> Layout
Definition views.hpp:248
constexpr auto from_eigen_layout(int l) -> Layout
Definition views.hpp:258
decltype(sizeof(0)) usize
Definition views.hpp:24
constexpr Layout colmajor
Definition views.hpp:244
constexpr auto to_eigen_layout(Layout l) -> int
Definition views.hpp:253
typename detail::unlref< T & >::Type unref
Definition views.hpp:495
constexpr Layout rowmajor
Definition views.hpp:245
VEG_INLINE auto l_mut() const noexcept -> MatrixViewMut< T, colmajor >
Definition views.hpp:1076
LdltViewMut(MatrixViewMut< T, colmajor > ld) noexcept
Definition views.hpp:1066
VEG_INLINE auto head(isize k) const -> LdltViewMut
Definition views.hpp:1094
VEG_INLINE auto d() const noexcept -> StridedVectorView< T >
Definition views.hpp:1080
VEG_INLINE auto d_mut() const noexcept -> StridedVectorViewMut< T >
Definition views.hpp:1084
VEG_INLINE auto as_const() const noexcept -> LdltView< T >
Definition views.hpp:1089
VEG_INLINE auto l() const noexcept -> MatrixView< T, colmajor >
Definition views.hpp:1072
VEG_INLINE auto tail(isize k) const -> LdltViewMut
Definition views.hpp:1098
VEG_INLINE auto d() const noexcept -> StridedVectorView< T >
Definition views.hpp:1044
VEG_INLINE auto head(isize k) const -> LdltView
Definition views.hpp:1049
LdltView(MatrixView< T, colmajor > ld) noexcept
Definition views.hpp:1037
VEG_INLINE auto l() const noexcept -> MatrixView< T, colmajor >
Definition views.hpp:1043
VEG_INLINE auto tail(isize k) const -> LdltView
Definition views.hpp:1053
VEG_INLINE auto row(isize r) const noexcept -> proxsuite::linalg::veg::meta::if_t<(L==rowmajor), VectorViewMut< T >, StridedVectorViewMut< T > >
Definition views.hpp:1001
VEG_INLINE auto operator()(isize row, isize col) const noexcept -> T &
Definition views.hpp:953
VEG_TEMPLATE(typename Mat, requires(LDLT_CONCEPT(eigen_view< Mat, T >) &&eigen::GetLayout< unref< Mat > >::value==L), VEG_INLINE MatrixViewMut,(, FromEigen),(mat, Mat &&)) noexcept
Definition views.hpp:936
VEG_INLINE auto trans() const noexcept -> MatrixViewMut< T, proxqp::flip_layout(L)>
Definition views.hpp:1007
VEG_INLINE auto to_eigen() const noexcept -> detail::EigenMatMapMut< T, L >
Definition views.hpp:1014
VEG_INLINE auto as_const() const noexcept -> MatrixView< T, L >
Definition views.hpp:1022
VEG_INLINE auto block(isize row, isize col, isize nrows, isize ncols) const noexcept -> MatrixViewMut
Definition views.hpp:957
VEG_INLINE auto col(isize c) const noexcept -> proxsuite::linalg::veg::meta::if_t<(L==colmajor), VectorViewMut< T >, StridedVectorViewMut< T > >
Definition views.hpp:995
VEG_INLINE MatrixViewMut(FromPtrRowsColsStride, T *_data, isize _rows, isize _cols, isize _outer_stride) noexcept
Definition views.hpp:924
VEG_INLINE auto ptr(isize row, isize col) const noexcept -> T *
Definition views.hpp:949
VEG_INLINE auto block(isize row, isize col, isize nrows, isize ncols) const noexcept -> MatrixView
Definition views.hpp:849
VEG_INLINE auto operator()(isize row, isize col) const noexcept -> T const &
Definition views.hpp:845
VEG_INLINE auto to_eigen() const noexcept -> detail::EigenMatMap< T, L >
Definition views.hpp:906
VEG_INLINE MatrixView(FromPtrRowsColsStride, T const *_data, isize _rows, isize _cols, isize _outer_stride) noexcept
Definition views.hpp:816
VEG_INLINE auto col(isize c) const noexcept -> proxsuite::linalg::veg::meta::if_t<(L==colmajor), VectorView< T >, StridedVectorView< T > >
Definition views.hpp:887
VEG_INLINE auto row(isize r) const noexcept -> proxsuite::linalg::veg::meta::if_t<(L==rowmajor), VectorView< T >, StridedVectorView< T > >
Definition views.hpp:893
VEG_INLINE auto trans() const noexcept -> MatrixView< T, proxqp::flip_layout(L)>
Definition views.hpp:899
VEG_TEMPLATE(typename Mat, requires(LDLT_CONCEPT(eigen_view< Mat, T >) &&eigen::GetLayout< unref< Mat > >::value==L), VEG_INLINE MatrixView,(, FromEigen),(mat, Mat const &)) noexcept
Definition views.hpp:828
VEG_INLINE auto ptr(isize row, isize col) const noexcept -> T const *
Definition views.hpp:841
VEG_TEMPLATE(typename Vec, requires(LDLT_CONCEPT(eigen_strided_vector_view_mut< Vec, T >)), VEG_INLINE StridedVectorViewMut,(, FromEigen),(vec, Vec &&)) noexcept
Definition views.hpp:759
VEG_INLINE auto as_const() const noexcept -> StridedVectorView< T >
Definition views.hpp:770
VEG_INLINE auto operator()(isize index) const noexcept -> T &
Definition views.hpp:783
VEG_INLINE auto ptr(isize index) const noexcept -> T *
Definition views.hpp:779
VEG_INLINE StridedVectorViewMut(FromPtrSizeStride, T *_data, isize _dim, isize _stride) noexcept
Definition views.hpp:749
VEG_INLINE auto to_eigen() const -> detail::EigenVecMapMut< T, Eigen::InnerStride< Eigen::Dynamic > >
Definition views.hpp:797
VEG_INLINE auto segment(isize i, isize size) const noexcept -> StridedVectorViewMut
Definition views.hpp:787
VEG_INLINE auto operator()(isize index) const noexcept -> T const &
Definition views.hpp:716
VEG_INLINE auto segment(isize i, isize size) const noexcept -> StridedVectorView
Definition views.hpp:720
VEG_INLINE auto ptr(isize index) const noexcept -> T const *
Definition views.hpp:712
VEG_INLINE auto to_eigen() const -> detail::EigenVecMap< T, Eigen::InnerStride< Eigen::Dynamic > >
Definition views.hpp:730
VEG_TEMPLATE(typename Vec, requires(LDLT_CONCEPT(eigen_strided_vector_view< Vec, T >)), VEG_INLINE StridedVectorView,(, FromEigen),(vec, Vec const &)) noexcept
Definition views.hpp:701
VEG_INLINE StridedVectorView(FromPtrSizeStride, T const *_data, isize _dim, isize _stride) noexcept
Definition views.hpp:691
VEG_INLINE auto segment(isize i, isize size) const noexcept -> VectorViewMut
Definition views.hpp:669
VEG_TEMPLATE(typename Vec, requires(LDLT_CONCEPT(eigen_vector_view_mut< Vec, T >)), VEG_INLINE VectorViewMut,(, FromEigen),(vec, Vec &&)) noexcept
Definition views.hpp:646
VEG_INLINE auto operator()(isize index) const noexcept -> T &
Definition views.hpp:665
VEG_INLINE auto to_eigen() const -> detail::VecMapMut< T >
Definition views.hpp:677
VEG_INLINE auto ptr(isize index) const noexcept -> T *
Definition views.hpp:664
VEG_INLINE auto as_const() const noexcept -> VectorView< T >
Definition views.hpp:656
VEG_INLINE VectorViewMut(FromPtrSize, T *_data, isize _dim) noexcept
Definition views.hpp:640
VEG_INLINE auto ptr(isize index) const noexcept -> T const *
Definition views.hpp:611
VEG_INLINE VectorView(FromPtrSize, T const *_data, isize _dim) noexcept
Definition views.hpp:595
VEG_INLINE auto segment(isize i, isize size) const noexcept -> VectorView
Definition views.hpp:619
VEG_INLINE auto to_eigen() const -> detail::VecMap< T >
Definition views.hpp:627
VEG_INLINE auto operator()(isize index) const noexcept -> T const &
Definition views.hpp:615
VEG_TEMPLATE(typename Vec, requires(LDLT_CONCEPT(eigen_vector_view< Vec, T >)), VEG_INLINE VectorView,(, FromEigen),(vec, Vec const &)) noexcept
Definition views.hpp:601
EigenAllowAlloc(EigenAllowAlloc &&)=delete
auto operator=(EigenAllowAlloc const &) -> EigenAllowAlloc &=delete
EigenAllowAlloc(EigenAllowAlloc const &)=delete
auto operator=(EigenAllowAlloc &&) -> EigenAllowAlloc &=delete
MatrixViewMut< Scalar, layout > C
Definition views.hpp:1404
static constexpr Layout layout
Definition views.hpp:1397
VectorViewMut< Scalar > u_box
Definition views.hpp:1409
VEG_INLINE constexpr auto as_const() const noexcept -> QpViewBox< Scalar >
Definition views.hpp:1411
MatrixViewMut< Scalar, layout > A
Definition views.hpp:1402
MatrixViewMut< Scalar, layout > H
Definition views.hpp:1399
VectorViewMut< Scalar > l_box
Definition views.hpp:1408
static constexpr Layout layout
Definition views.hpp:1357
MatrixView< Scalar, layout > H
Definition views.hpp:1359
MatrixView< Scalar, layout > C
Definition views.hpp:1364
MatrixView< Scalar, layout > A
Definition views.hpp:1362
MatrixViewMut< T, layout > A
Definition views.hpp:1380
MatrixViewMut< T, layout > C
Definition views.hpp:1382
VEG_INLINE constexpr auto as_const() const noexcept -> QpView< T >
Definition views.hpp:1385
MatrixViewMut< T, layout > H
Definition views.hpp:1377
static constexpr Layout layout
Definition views.hpp:1375
MatrixView< T, layout > A
Definition views.hpp:1348
MatrixView< T, layout > H
Definition views.hpp:1345
static constexpr Layout layout
Definition views.hpp:1343
MatrixView< T, layout > C
Definition views.hpp:1350
auto operator()(T x) const -> T
Definition views.hpp:1453
auto operator()(Eigen::MatrixBase< D > const &mat) const -> typename D::Scalar
Definition views.hpp:1432
auto operator()(T x, T y) const -> T
Definition views.hpp:1423
auto operator()(T x) const -> T
Definition views.hpp:1444
VEG_INLINE ~Defer() noexcept(noexcept(VEG_FWD(fn)()))
Definition views.hpp:88
Eigen::InnerStride< Eigen::Dynamic > NextColStride
Definition views.hpp:288
static VEG_INLINE auto next_row_stride(isize outer_stride) noexcept -> NextRowStride
Definition views.hpp:289
static VEG_INLINE auto next_col_stride(isize outer_stride) noexcept -> NextColStride
Definition views.hpp:295
static VEG_INLINE constexpr auto offset(T *ptr, isize row, isize col, isize outer_stride) noexcept -> T *
Definition views.hpp:279
static VEG_INLINE void transpose_if_rowmajor(T *ptr, isize dim, isize outer_stride)
Definition views.hpp:303
static VEG_INLINE auto next_row_stride(isize outer_stride) noexcept -> NextRowStride
Definition views.hpp:331
static VEG_INLINE void transpose_if_rowmajor(T *ptr, isize dim, isize outer_stride)
Definition views.hpp:339
static VEG_INLINE constexpr auto offset(T *ptr, isize row, isize col, isize outer_stride) noexcept -> T *
Definition views.hpp:315
Eigen::InnerStride< Eigen::Dynamic > NextRowStride
Definition views.hpp:324
static VEG_INLINE auto next_col_stride(isize outer_stride) noexcept -> NextColStride
Definition views.hpp:325
NoCopy(NoCopy const &)=delete
auto operator=(NoCopy &&) -> NoCopy &=delete
auto operator=(NoCopy const &) -> NoCopy &=delete
static void fn(T *dest, usize n)
Definition views.hpp:164
VEG_INLINE constexpr auto operator()(Fn fn) const -> Defer< Fn >
Definition views.hpp:95
VEG_INLINE constexpr auto operator()(T const &a, T const &b) const -> T const &
Definition views.hpp:103
VEG_INLINE auto operator()(std::initializer_list< T > list) const -> T
Definition views.hpp:141
VEG_INLINE constexpr auto operator()(T a, T b) const -> T
Definition views.hpp:111