This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
View | Details | Raw Unified | Return to bug 1658
Collapse All | Expand All

(-)a/Eigen/src/Core/SelfAdjointView.h (+13 lines)
Lines 56-71 template<typename _MatrixType, unsigned Link Here
56
    typedef typename internal::traits<SelfAdjointView>::MatrixTypeNested MatrixTypeNested;
56
    typedef typename internal::traits<SelfAdjointView>::MatrixTypeNested MatrixTypeNested;
57
    typedef typename internal::traits<SelfAdjointView>::MatrixTypeNestedCleaned MatrixTypeNestedCleaned;
57
    typedef typename internal::traits<SelfAdjointView>::MatrixTypeNestedCleaned MatrixTypeNestedCleaned;
58
    typedef MatrixTypeNestedCleaned NestedExpression;
58
    typedef MatrixTypeNestedCleaned NestedExpression;
59
59
60
    /** \brief The type of coefficients in this matrix */
60
    /** \brief The type of coefficients in this matrix */
61
    typedef typename internal::traits<SelfAdjointView>::Scalar Scalar; 
61
    typedef typename internal::traits<SelfAdjointView>::Scalar Scalar; 
62
    typedef typename MatrixType::StorageIndex StorageIndex;
62
    typedef typename MatrixType::StorageIndex StorageIndex;
63
    typedef typename internal::remove_all<typename MatrixType::ConjugateReturnType>::type MatrixConjugateReturnType;
63
    typedef typename internal::remove_all<typename MatrixType::ConjugateReturnType>::type MatrixConjugateReturnType;
64
    typedef SelfAdjointView<typename internal::add_const<MatrixType>::type, UpLo> ConstSelfAdjointView;
64
65
65
    enum {
66
    enum {
66
      Mode = internal::traits<SelfAdjointView>::Mode,
67
      Mode = internal::traits<SelfAdjointView>::Mode,
67
      Flags = internal::traits<SelfAdjointView>::Flags,
68
      Flags = internal::traits<SelfAdjointView>::Flags,
68
      TransposeMode = ((Mode & Upper) ? Lower : 0) | ((Mode & Lower) ? Upper : 0)
69
      TransposeMode = ((Mode & Upper) ? Lower : 0) | ((Mode & Lower) ? Upper : 0)
69
    };
70
    };
70
    typedef typename MatrixType::PlainObject PlainObject;
71
    typedef typename MatrixType::PlainObject PlainObject;
71
72
Lines 192-207 template<typename _MatrixType, unsigned Link Here
192
    }
193
    }
193
194
194
    typedef SelfAdjointView<const MatrixConjugateReturnType,UpLo> ConjugateReturnType;
195
    typedef SelfAdjointView<const MatrixConjugateReturnType,UpLo> ConjugateReturnType;
195
    /** \sa MatrixBase::conjugate() const */
196
    /** \sa MatrixBase::conjugate() const */
196
    EIGEN_DEVICE_FUNC
197
    EIGEN_DEVICE_FUNC
197
    inline const ConjugateReturnType conjugate() const
198
    inline const ConjugateReturnType conjugate() const
198
    { return ConjugateReturnType(m_matrix.conjugate()); }
199
    { return ConjugateReturnType(m_matrix.conjugate()); }
199
200
201
    /** \returns an expression of the complex conjugate of \c *this if Cond==true,
202
     *           returns \c *this otherwise.
203
     */
204
    template<bool Cond>
205
    EIGEN_DEVICE_FUNC
206
    inline typename internal::conditional<Cond,ConjugateReturnType,ConstSelfAdjointView>::type
207
    conjugateIf() const
208
    {
209
      typedef typename internal::conditional<Cond,ConjugateReturnType,ConstSelfAdjointView>::type ReturnType;
210
      return ReturnType(m_matrix.template conjugateIf<Cond>());
211
    }
212
200
    typedef SelfAdjointView<const typename MatrixType::AdjointReturnType,TransposeMode> AdjointReturnType;
213
    typedef SelfAdjointView<const typename MatrixType::AdjointReturnType,TransposeMode> AdjointReturnType;
201
    /** \sa MatrixBase::adjoint() const */
214
    /** \sa MatrixBase::adjoint() const */
202
    EIGEN_DEVICE_FUNC
215
    EIGEN_DEVICE_FUNC
203
    inline const AdjointReturnType adjoint() const
216
    inline const AdjointReturnType adjoint() const
204
    { return AdjointReturnType(m_matrix.adjoint()); }
217
    { return AdjointReturnType(m_matrix.adjoint()); }
205
218
206
    typedef SelfAdjointView<typename MatrixType::TransposeReturnType,TransposeMode> TransposeReturnType;
219
    typedef SelfAdjointView<typename MatrixType::TransposeReturnType,TransposeMode> TransposeReturnType;
207
     /** \sa MatrixBase::transpose() */
220
     /** \sa MatrixBase::transpose() */
(-)a/Eigen/src/Core/TriangularMatrix.h (+13 lines)
Lines 193-208 template<typename _MatrixType, unsigned Link Here
193
    typedef typename internal::traits<TriangularView>::Scalar Scalar;
193
    typedef typename internal::traits<TriangularView>::Scalar Scalar;
194
    typedef _MatrixType MatrixType;
194
    typedef _MatrixType MatrixType;
195
195
196
  protected:
196
  protected:
197
    typedef typename internal::traits<TriangularView>::MatrixTypeNested MatrixTypeNested;
197
    typedef typename internal::traits<TriangularView>::MatrixTypeNested MatrixTypeNested;
198
    typedef typename internal::traits<TriangularView>::MatrixTypeNestedNonRef MatrixTypeNestedNonRef;
198
    typedef typename internal::traits<TriangularView>::MatrixTypeNestedNonRef MatrixTypeNestedNonRef;
199
199
200
    typedef typename internal::remove_all<typename MatrixType::ConjugateReturnType>::type MatrixConjugateReturnType;
200
    typedef typename internal::remove_all<typename MatrixType::ConjugateReturnType>::type MatrixConjugateReturnType;
201
    typedef TriangularView<typename internal::add_const<MatrixType>::type, _Mode> ConstTriangularView;
201
    
202
    
202
  public:
203
  public:
203
204
204
    typedef typename internal::traits<TriangularView>::StorageKind StorageKind;
205
    typedef typename internal::traits<TriangularView>::StorageKind StorageKind;
205
    typedef typename internal::traits<TriangularView>::MatrixTypeNestedCleaned NestedExpression;
206
    typedef typename internal::traits<TriangularView>::MatrixTypeNestedCleaned NestedExpression;
206
207
207
    enum {
208
    enum {
208
      Mode = _Mode,
209
      Mode = _Mode,
Lines 238-253 template<typename _MatrixType, unsigned Link Here
238
    NestedExpression& nestedExpression() { return m_matrix; }
239
    NestedExpression& nestedExpression() { return m_matrix; }
239
    
240
    
240
    typedef TriangularView<const MatrixConjugateReturnType,Mode> ConjugateReturnType;
241
    typedef TriangularView<const MatrixConjugateReturnType,Mode> ConjugateReturnType;
241
    /** \sa MatrixBase::conjugate() const */
242
    /** \sa MatrixBase::conjugate() const */
242
    EIGEN_DEVICE_FUNC
243
    EIGEN_DEVICE_FUNC
243
    inline const ConjugateReturnType conjugate() const
244
    inline const ConjugateReturnType conjugate() const
244
    { return ConjugateReturnType(m_matrix.conjugate()); }
245
    { return ConjugateReturnType(m_matrix.conjugate()); }
245
246
247
    /** \returns an expression of the complex conjugate of \c *this if Cond==true,
248
     *           returns \c *this otherwise.
249
     */
250
    template<bool Cond>
251
    EIGEN_DEVICE_FUNC
252
    inline typename internal::conditional<Cond,ConjugateReturnType,ConstTriangularView>::type
253
    conjugateIf() const
254
    {
255
      typedef typename internal::conditional<Cond,ConjugateReturnType,ConstTriangularView>::type ReturnType;
256
      return ReturnType(m_matrix.template conjugateIf<Cond>());
257
    }
258
246
    typedef TriangularView<const typename MatrixType::AdjointReturnType,TransposeMode> AdjointReturnType;
259
    typedef TriangularView<const typename MatrixType::AdjointReturnType,TransposeMode> AdjointReturnType;
247
    /** \sa MatrixBase::adjoint() const */
260
    /** \sa MatrixBase::adjoint() const */
248
    EIGEN_DEVICE_FUNC
261
    EIGEN_DEVICE_FUNC
249
    inline const AdjointReturnType adjoint() const
262
    inline const AdjointReturnType adjoint() const
250
    { return AdjointReturnType(m_matrix.adjoint()); }
263
    { return AdjointReturnType(m_matrix.adjoint()); }
251
264
252
    typedef TriangularView<typename MatrixType::TransposeReturnType,TransposeMode> TransposeReturnType;
265
    typedef TriangularView<typename MatrixType::TransposeReturnType,TransposeMode> TransposeReturnType;
253
     /** \sa MatrixBase::transpose() */
266
     /** \sa MatrixBase::transpose() */
(-)a/Eigen/src/LU/PartialPivLU.h (-15 / +10 lines)
Lines 241-276 template<typename _MatrixType> class Par Link Here
241
241
242
      // Step 3
242
      // Step 3
243
      m_lu.template triangularView<Upper>().solveInPlace(dst);
243
      m_lu.template triangularView<Upper>().solveInPlace(dst);
244
    }
244
    }
245
245
246
    template<bool Conjugate, typename RhsType, typename DstType>
246
    template<bool Conjugate, typename RhsType, typename DstType>
247
    EIGEN_DEVICE_FUNC
247
    EIGEN_DEVICE_FUNC
248
    void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const {
248
    void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const {
249
     /* The decomposition PA = LU can be rewritten as A = P^{-1} L U.
249
     /* The decomposition PA = LU can be rewritten as A^T = U^T L^T P.
250
      * So we proceed as follows:
250
      * So we proceed as follows:
251
      * Step 1: compute c = Pb.
251
      * Step 1: compute c as the solution to L^T c = b
252
      * Step 2: replace c by the solution x to Lx = c.
252
      * Step 2: replace c by the solution x to U^T x = c.
253
      * Step 3: replace c by the solution x to Ux = c.
253
      * Step 3: update  c = P^-1 c.
254
      */
254
      */
255
255
256
      eigen_assert(rhs.rows() == m_lu.cols());
256
      eigen_assert(rhs.rows() == m_lu.cols());
257
257
258
      if (Conjugate) {
258
      // Step 1
259
        // Step 1
259
      dst = m_lu.template triangularView<Upper>().transpose()
260
        dst = m_lu.template triangularView<Upper>().adjoint().solve(rhs);
260
                .template conjugateIf<Conjugate>().solve(rhs);
261
        // Step 2
261
      // Step 2
262
        m_lu.template triangularView<UnitLower>().adjoint().solveInPlace(dst);
262
      m_lu.template triangularView<UnitLower>().transpose()
263
      } else {
263
          .template conjugateIf<Conjugate>().solveInPlace(dst);
264
        // Step 1
265
        dst = m_lu.template triangularView<Upper>().transpose().solve(rhs);
266
        // Step 2
267
        m_lu.template triangularView<UnitLower>().transpose().solveInPlace(dst);
268
      }
269
      // Step 3
264
      // Step 3
270
      dst = permutationP().transpose() * dst;
265
      dst = permutationP().transpose() * dst;
271
    }
266
    }
272
    #endif
267
    #endif
273
268
274
  protected:
269
  protected:
275
270
276
    static void check_template_parameters()
271
    static void check_template_parameters()
(-)a/Eigen/src/plugins/CommonCwiseUnaryOps.h (+14 lines)
Lines 71-86 EIGEN_DOC_UNARY_ADDONS(conjugate,complex Link Here
71
/// \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_conj">Math functions</a>, MatrixBase::adjoint()
71
/// \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_conj">Math functions</a>, MatrixBase::adjoint()
72
EIGEN_DEVICE_FUNC
72
EIGEN_DEVICE_FUNC
73
inline ConjugateReturnType
73
inline ConjugateReturnType
74
conjugate() const
74
conjugate() const
75
{
75
{
76
  return ConjugateReturnType(derived());
76
  return ConjugateReturnType(derived());
77
}
77
}
78
78
79
/// \returns an expression of the complex conjugate of \c *this if Cond==true, returns derived() otherwise.
80
///
81
EIGEN_DOC_UNARY_ADDONS(conjugate,complex conjugate)
82
///
83
/// \sa conjugate()
84
template<bool Cond>
85
EIGEN_DEVICE_FUNC
86
inline typename internal::conditional<Cond,ConjugateReturnType,const Derived&>::type
87
conjugateIf() const
88
{
89
  typedef typename internal::conditional<Cond,ConjugateReturnType,const Derived&>::type ReturnType;
90
  return ReturnType(derived());
91
}
92
79
/// \returns a read-only expression of the real part of \c *this.
93
/// \returns a read-only expression of the real part of \c *this.
80
///
94
///
81
EIGEN_DOC_UNARY_ADDONS(real,real part function)
95
EIGEN_DOC_UNARY_ADDONS(real,real part function)
82
///
96
///
83
/// \sa imag()
97
/// \sa imag()
84
EIGEN_DEVICE_FUNC
98
EIGEN_DEVICE_FUNC
85
inline RealReturnType
99
inline RealReturnType
86
real() const { return RealReturnType(derived()); }
100
real() const { return RealReturnType(derived()); }
(-)a/test/adjoint.cpp (+3 lines)
Lines 138-153 template<typename MatrixType> void adjoi Link Here
138
  m3.transposeInPlace();
138
  m3.transposeInPlace();
139
  VERIFY_IS_APPROX(m3,m1.conjugate());
139
  VERIFY_IS_APPROX(m3,m1.conjugate());
140
140
141
  // check mixed dot product
141
  // check mixed dot product
142
  typedef Matrix<RealScalar, MatrixType::RowsAtCompileTime, 1> RealVectorType;
142
  typedef Matrix<RealScalar, MatrixType::RowsAtCompileTime, 1> RealVectorType;
143
  RealVectorType rv1 = RealVectorType::Random(rows);
143
  RealVectorType rv1 = RealVectorType::Random(rows);
144
  VERIFY_IS_APPROX(v1.dot(rv1.template cast<Scalar>()), v1.dot(rv1));
144
  VERIFY_IS_APPROX(v1.dot(rv1.template cast<Scalar>()), v1.dot(rv1));
145
  VERIFY_IS_APPROX(rv1.template cast<Scalar>().dot(v1), rv1.dot(v1));
145
  VERIFY_IS_APPROX(rv1.template cast<Scalar>().dot(v1), rv1.dot(v1));
146
147
  VERIFY( is_same_type(m1,m1.template conjugateIf<false>()) );
148
  VERIFY( is_same_type(m1.conjugate(),m1.template conjugateIf<true>()) );
146
}
149
}
147
150
148
template<int>
151
template<int>
149
void adjoint_extra()
152
void adjoint_extra()
150
{
153
{
151
  MatrixXcf a(10,10), b(10,10);
154
  MatrixXcf a(10,10), b(10,10);
152
  VERIFY_RAISES_ASSERT(a = a.transpose());
155
  VERIFY_RAISES_ASSERT(a = a.transpose());
153
  VERIFY_RAISES_ASSERT(a = a.transpose() + b);
156
  VERIFY_RAISES_ASSERT(a = a.transpose() + b);
(-)a/test/triangular.cpp (+16 lines)
Lines 124-139 template<typename MatrixType> void trian Link Here
124
  m1up = m1.template triangularView<Upper>();
124
  m1up = m1.template triangularView<Upper>();
125
  VERIFY_IS_APPROX(m1.template selfadjointView<Upper>().template triangularView<Upper>().toDenseMatrix(), m1up);
125
  VERIFY_IS_APPROX(m1.template selfadjointView<Upper>().template triangularView<Upper>().toDenseMatrix(), m1up);
126
  VERIFY_IS_APPROX(m1up.template selfadjointView<Upper>().template triangularView<Upper>().toDenseMatrix(), m1up);
126
  VERIFY_IS_APPROX(m1up.template selfadjointView<Upper>().template triangularView<Upper>().toDenseMatrix(), m1up);
127
  VERIFY_IS_APPROX(m1.template selfadjointView<Upper>().template triangularView<Lower>().toDenseMatrix(), m1up.adjoint());
127
  VERIFY_IS_APPROX(m1.template selfadjointView<Upper>().template triangularView<Lower>().toDenseMatrix(), m1up.adjoint());
128
  VERIFY_IS_APPROX(m1up.template selfadjointView<Upper>().template triangularView<Lower>().toDenseMatrix(), m1up.adjoint());
128
  VERIFY_IS_APPROX(m1up.template selfadjointView<Upper>().template triangularView<Lower>().toDenseMatrix(), m1up.adjoint());
129
129
130
  VERIFY_IS_APPROX(m1.template selfadjointView<Upper>().diagonal(), m1.diagonal());
130
  VERIFY_IS_APPROX(m1.template selfadjointView<Upper>().diagonal(), m1.diagonal());
131
131
132
  m3.setRandom();
133
  const MatrixType& m3c(m3);
134
  VERIFY( is_same_type(m3c.template triangularView<Lower>(),m3.template triangularView<Lower>().template conjugateIf<false>()) );
135
  VERIFY( is_same_type(m3c.template triangularView<Lower>().conjugate(),m3.template triangularView<Lower>().template conjugateIf<true>()) );
136
  VERIFY_IS_APPROX(m3.template triangularView<Lower>().template conjugateIf<true>().toDenseMatrix(),
137
                   m3.conjugate().template triangularView<Lower>().toDenseMatrix());
138
  VERIFY_IS_APPROX(m3.template triangularView<Lower>().template conjugateIf<false>().toDenseMatrix(),
139
                   m3.template triangularView<Lower>().toDenseMatrix());
140
141
  VERIFY( is_same_type(m3c.template selfadjointView<Lower>(),m3.template selfadjointView<Lower>().template conjugateIf<false>()) );
142
  VERIFY( is_same_type(m3c.template selfadjointView<Lower>().conjugate(),m3.template selfadjointView<Lower>().template conjugateIf<true>()) );
143
  VERIFY_IS_APPROX(m3.template selfadjointView<Lower>().template conjugateIf<true>().toDenseMatrix(),
144
                   m3.conjugate().template selfadjointView<Lower>().toDenseMatrix());
145
  VERIFY_IS_APPROX(m3.template selfadjointView<Lower>().template conjugateIf<false>().toDenseMatrix(),
146
                   m3.template selfadjointView<Lower>().toDenseMatrix());
147
132
}
148
}
133
149
134
150
135
template<typename MatrixType> void triangular_rect(const MatrixType& m)
151
template<typename MatrixType> void triangular_rect(const MatrixType& m)
136
{
152
{
137
  typedef typename MatrixType::Scalar Scalar;
153
  typedef typename MatrixType::Scalar Scalar;
138
  typedef typename NumTraits<Scalar>::Real RealScalar;
154
  typedef typename NumTraits<Scalar>::Real RealScalar;
139
  enum { Rows =  MatrixType::RowsAtCompileTime, Cols =  MatrixType::ColsAtCompileTime };
155
  enum { Rows =  MatrixType::RowsAtCompileTime, Cols =  MatrixType::ColsAtCompileTime };

Return to bug 1658