GCC Code Coverage Report


Directory: Bembel/src/
File: Bembel/src/H2Matrix/EigenHelper/H2CwiseBinaryOp.hpp
Date: 2024-09-30 07:01:38
Exec Total Coverage
Lines: 22 22 100.0%
Functions: 53 53 100.0%
Branches: 7 14 50.0%

Line Branch Exec Source
1 // This file is part of Bembel, the higher order C++ boundary element library.
2 //
3 // Copyright (C) 2022 see <http://www.bembel.eu>
4 //
5 // It was written as part of a cooperation of J. Doelz, H. Harbrecht, S. Kurz,
6 // M. Multerer, S. Schoeps, and F. Wolf at Technische Universitaet Darmstadt,
7 // Universitaet Basel, and Universita della Svizzera italiana, Lugano. This
8 // source code is subject to the GNU General Public License version 3 and
9 // provided WITHOUT ANY WARRANTY, see <http://www.bembel.eu> for further
10 // information.
11 #ifndef BEMBEL_SRC_H2MATRIX_EIGENHELPER_H2CWISEBINARYOP_HPP_
12 #define BEMBEL_SRC_H2MATRIX_EIGENHELPER_H2CWISEBINARYOP_HPP_
13
14 // The contents of this file are a modification of the file
15 // SparseCwiseBinaryOp.h from the Eigen library
16 namespace Eigen {
17
18 template <typename BinaryOp, typename Lhs, typename Rhs>
19 class CwiseBinaryOpImpl<BinaryOp, Lhs, Rhs, H2>
20 : public H2MatrixBase<CwiseBinaryOp<BinaryOp, Lhs, Rhs>> {
21 public:
22 typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> Derived;
23 typedef H2MatrixBase<Derived> Base;
24 EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
25 138 CwiseBinaryOpImpl() {
26 EIGEN_STATIC_ASSERT(
27 ((!internal::is_same<
28 typename internal::traits<Lhs>::StorageKind,
29 typename internal::traits<Rhs>::StorageKind>::value) ||
30 ((internal::evaluator<Lhs>::Flags & RowMajorBit) ==
31 (internal::evaluator<Rhs>::Flags & RowMajorBit))),
32 THE_STORAGE_ORDER_OF_BOTH_SIDES_MUST_MATCH);
33 138 }
34 };
35
36 namespace internal {
37
38 // brute force solution to allow the use of CwiseBinaryOps in solvers
39 template <typename BinaryOp, typename Lhs, typename Rhs>
40 struct is_ref_compatible<CwiseBinaryOp<BinaryOp, Lhs, Rhs>> {
41 enum { value = false };
42 };
43 template <typename BinaryOp, typename Lhs, typename Rhs>
44 struct is_ref_compatible<const CwiseBinaryOp<BinaryOp, Lhs, Rhs>>
45 : is_ref_compatible<CwiseBinaryOp<BinaryOp, Lhs, Rhs>> {};
46
47 // allow H2+H2, H2-H2, etc.
48 template <typename BinaryOp, typename Lhs, typename Rhs>
49 struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, H2, H2>
50 : evaluator_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs>> {
51 protected:
52 typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType;
53 typedef typename traits<XprType>::Scalar Scalar;
54 typedef typename XprType::StorageIndex StorageIndex;
55
56 public:
57 enum {
58 CoeffReadCost = HugeCost,
59 Flags = (XprType::Flags & ~RowMajorBit) | (int(Rhs::Flags) & RowMajorBit)
60 };
61
62 explicit binary_evaluator(const XprType& xpr)
63 : m_functor(xpr.functor()),
64 m_lhsImpl(xpr.lhs()),
65 m_rhsImpl(xpr.rhs()),
66 m_expr(xpr) {
67 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
68 }
69
70 protected:
71 const BinaryOp m_functor;
72 evaluator<Lhs> m_lhsImpl;
73 evaluator<Rhs> m_rhsImpl;
74 const XprType& m_expr;
75 };
76 // interaction structs with dense
77 template <typename BinaryOp, typename Lhs, typename Rhs>
78 struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, IndexBased, H2>
79 : binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, H2, H2> {};
80 template <typename BinaryOp, typename Lhs, typename Rhs>
81 struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, H2, IndexBased>
82 : binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, H2, H2> {};
83 // interaction structs with sparse
84 template <typename BinaryOp, typename Lhs, typename Rhs>
85 struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, IteratorBased, H2>
86 : binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, H2, H2> {};
87 template <typename BinaryOp, typename Lhs, typename Rhs>
88 struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, H2, IteratorBased>
89 : binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, H2, H2> {};
90
91 } // namespace internal
92
93 /***************************************************************************
94 * Implementation of H2MatrixBase and H2Cwise functions/operators
95 ***************************************************************************/
96
97 template <typename DenseDerived, typename H2Derived>
98 EIGEN_STRONG_INLINE const
99 CwiseBinaryOp<internal::scalar_sum_op<typename DenseDerived::Scalar,
100 typename H2Derived::Scalar>,
101 const DenseDerived, const H2Derived>
102 3 operator+(const MatrixBase<DenseDerived>& a,
103 const H2MatrixBase<H2Derived>& b) {
104 return CwiseBinaryOp<internal::scalar_sum_op<typename DenseDerived::Scalar,
105 typename H2Derived::Scalar>,
106 3 const DenseDerived, const H2Derived>(a.derived(),
107
1/2
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
6 b.derived());
108 }
109
110 template <typename H2Derived, typename DenseDerived>
111 EIGEN_STRONG_INLINE const
112 CwiseBinaryOp<internal::scalar_sum_op<typename H2Derived::Scalar,
113 typename DenseDerived::Scalar>,
114 const H2Derived, const DenseDerived>
115 10 operator+(const H2MatrixBase<H2Derived>& a,
116 const MatrixBase<DenseDerived>& b) {
117 return CwiseBinaryOp<internal::scalar_sum_op<typename H2Derived::Scalar,
118 typename DenseDerived::Scalar>,
119 10 const H2Derived, const DenseDerived>(a.derived(),
120
1/2
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
20 b.derived());
121 }
122
123 template <typename SparseDerived, typename H2Derived>
124 EIGEN_STRONG_INLINE const
125 CwiseBinaryOp<internal::scalar_sum_op<typename SparseDerived::Scalar,
126 typename H2Derived::Scalar>,
127 const SparseDerived, const H2Derived>
128 3 operator+(const SparseMatrixBase<SparseDerived>& a,
129 const H2MatrixBase<H2Derived>& b) {
130 return CwiseBinaryOp<internal::scalar_sum_op<typename SparseDerived::Scalar,
131 typename H2Derived::Scalar>,
132 3 const SparseDerived, const H2Derived>(a.derived(),
133
1/2
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
6 b.derived());
134 }
135
136 template <typename H2Derived, typename SparseDerived>
137 EIGEN_STRONG_INLINE const
138 CwiseBinaryOp<internal::scalar_sum_op<typename H2Derived::Scalar,
139 typename SparseDerived::Scalar>,
140 const H2Derived, const SparseDerived>
141 10 operator+(const H2MatrixBase<H2Derived>& a,
142 const SparseMatrixBase<SparseDerived>& b) {
143 return CwiseBinaryOp<internal::scalar_sum_op<typename H2Derived::Scalar,
144 typename SparseDerived::Scalar>,
145 10 const H2Derived, const SparseDerived>(a.derived(),
146
1/2
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
20 b.derived());
147 }
148
149 template <typename DenseDerived, typename H2Derived>
150 EIGEN_STRONG_INLINE const
151 CwiseBinaryOp<internal::scalar_difference_op<typename DenseDerived::Scalar,
152 typename H2Derived::Scalar>,
153 const DenseDerived, const H2Derived>
154 3 operator-(const MatrixBase<DenseDerived>& a,
155 const H2MatrixBase<H2Derived>& b) {
156 return CwiseBinaryOp<
157 internal::scalar_difference_op<typename DenseDerived::Scalar,
158 typename H2Derived::Scalar>,
159
1/2
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 const DenseDerived, const H2Derived>(a.derived(), b.derived());
160 }
161
162 template <typename H2Derived, typename DenseDerived>
163 EIGEN_STRONG_INLINE const
164 CwiseBinaryOp<internal::scalar_difference_op<typename H2Derived::Scalar,
165 typename DenseDerived::Scalar>,
166 const H2Derived, const DenseDerived>
167 10 operator-(const H2MatrixBase<H2Derived>& a,
168 const MatrixBase<DenseDerived>& b) {
169 return CwiseBinaryOp<
170 internal::scalar_difference_op<typename H2Derived::Scalar,
171 typename DenseDerived::Scalar>,
172
1/2
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
10 const H2Derived, const DenseDerived>(a.derived(), b.derived());
173 }
174
175 template <typename SparseDerived, typename H2Derived>
176 EIGEN_STRONG_INLINE const
177 CwiseBinaryOp<internal::scalar_difference_op<typename SparseDerived::Scalar,
178 typename H2Derived::Scalar>,
179 const SparseDerived, const H2Derived>
180 3 operator-(const SparseMatrixBase<SparseDerived>& a,
181 const H2MatrixBase<H2Derived>& b) {
182 return CwiseBinaryOp<
183 internal::scalar_difference_op<typename SparseDerived::Scalar,
184 typename H2Derived::Scalar>,
185
1/2
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 const SparseDerived, const H2Derived>(a.derived(), b.derived());
186 }
187
188 template <typename H2Derived, typename SparseDerived>
189 EIGEN_STRONG_INLINE const CwiseBinaryOp<
190 internal::scalar_difference_op<typename H2Derived::Scalar,
191 typename SparseDerived::Scalar>,
192 const H2Derived, const SparseDerived>
193 5 operator-(const H2MatrixBase<H2Derived>& a,
194 const SparseMatrixBase<SparseDerived>& b) {
195 return CwiseBinaryOp<
196 internal::scalar_difference_op<typename H2Derived::Scalar,
197 typename SparseDerived::Scalar>,
198 5 const H2Derived, const SparseDerived>(a.derived(), b.derived());
199 }
200
201 } // end namespace Eigen
202
203 #endif // BEMBEL_SRC_H2MATRIX_EIGENHELPER_H2CWISEBINARYOP_HPP_
204