[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/eigen2/Eigen
From:       Gael Guennebaud <g.gael () free ! fr>
Date:       2008-05-29 22:33:09
Message-ID: 1212100389.056873.20120.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 814312 by ggael:

Added ArrayBit to get the ability to manipulate a Matrix like a simple scalar.
In particular this flag changes the behavior of operator* to a coeff wise product.


 M  +1 -0      Core  
 A             src/Core/ArrayBase.h   [License: GPL (v3+) LGPL (v3+)]
 M  +20 -12    src/Core/MatrixBase.h  
 M  +3 -2      src/Core/Product.h  
 M  +6 -4      src/Core/util/Constants.h  
 M  +1 -0      src/Core/util/ForwardDeclarations.h  
 M  +2 -2      src/Core/util/Meta.h  


--- branches/work/eigen2/Eigen/Core #814311:814312
@@ -27,6 +27,7 @@
 
 #include "src/Core/Functors.h"
 #include "src/Core/MatrixBase.h"
+#include "src/Core/ArrayBase.h"
 #include "src/Core/Coeffs.h"
 #include "src/Core/Assign.h"
 #include "src/Core/MatrixStorage.h"
--- branches/work/eigen2/Eigen/src/Core/MatrixBase.h #814311:814312
@@ -49,7 +49,7 @@
   *
   * \nosubgrouping
   */
-template<typename Derived> class MatrixBase
+template<typename Derived> class MatrixBase : public ArrayBase<Derived>
 {
     struct CommaInitializer;
 
@@ -182,6 +182,24 @@
     };
     /** Represents a product scalar-matrix */
     typedef CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived> \
ScalarMultipleReturnType; +    /** */
+    template<typename OtherDerived>
+    struct ProductReturnType
+    {
+      typedef typename ei_meta_if<
+            (Derived::Flags & OtherDerived::Flags & ArrayBit),
+            CwiseBinaryOp<ei_scalar_product_op<typename ei_traits<Derived>::Scalar>, \
Derived, OtherDerived>, +            Product<Derived,OtherDerived>
+          >::ret Type;
+    };
+    /** the return type of MatrixBase::conjugate() */
+    typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex,
+                        CwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, Derived>,
+                        Derived&
+                     >::ret ConjugateReturnType;
+    /** the return type of MatrixBase::adjoint() */
+    typedef Transpose<NestByValue<typename ei_unref<ConjugateReturnType>::type> >
+            AdjointReturnType;
     //@}
 
     /// \name Copying and initialization
@@ -281,7 +299,7 @@
       */
     //@{
     template<typename OtherDerived>
-    const Product<Derived,OtherDerived>
+    const typename ProductReturnType<OtherDerived>::Type
     operator*(const MatrixBase<OtherDerived> &other) const;
 
     template<typename OtherDerived>
@@ -303,16 +321,6 @@
 
     Transpose<Derived> transpose();
     const Transpose<Derived> transpose() const;
-
-    /** the return type of MatrixBase::conjugate() */
-    typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex,
-                        CwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, Derived>,
-                        Derived&
-                     >::ret ConjugateReturnType;
-    /** the return type of MatrixBase::adjoint() */
-    typedef Transpose<
-                NestByValue<typename ei_unref<ConjugateReturnType>::type>
-              > AdjointReturnType;
     const AdjointReturnType adjoint() const;
     //@}
 
--- branches/work/eigen2/Eigen/src/Core/Product.h #814311:814312
@@ -320,10 +320,11 @@
   */
 template<typename Derived>
 template<typename OtherDerived>
-inline const Product<Derived,OtherDerived>
+inline const typename MatrixBase<Derived>::template \
ProductReturnType<OtherDerived>::Type  MatrixBase<Derived>::operator*(const \
MatrixBase<OtherDerived> &other) const  {
-  return Product<Derived,OtherDerived>(derived(), other.derived());
+  assert( (Derived::Flags&ArrayBit) == (OtherDerived::Flags) );
+  return typename ProductReturnType<OtherDerived>::Type(derived(), other.derived());
 }
 
 /** replaces \c *this by \c *this * \a other.
--- branches/work/eigen2/Eigen/src/Core/util/Constants.h #814311:814312
@@ -42,15 +42,17 @@
 const unsigned int ZeroDiagBit = 0x40;      ///< means all diagonal coefficients are \
equal to 0  const unsigned int UnitDiagBit = 0x80;      ///< means all diagonal \
coefficients are equal to 1  const unsigned int SelfAdjointBit = 0x100;  ///< means \
                the matrix is selfadjoint (M=M*).
-const unsigned int UpperTriangularBit = 0x200;    ///< means the strictly triangular \
                lower part is 0
-const unsigned int LowerTriangularBit = 0x400;    ///< means the strictly triangular \
                upper part is 0
-const unsigned int DirectAccessBit = 0x800; ///< means the underlying matrix data \
can be direclty accessed +const unsigned int UpperTriangularBit = 0x200;  ///< means \
the strictly triangular lower part is 0 +const unsigned int LowerTriangularBit = \
0x400;  ///< means the strictly triangular upper part is 0 +const unsigned int \
DirectAccessBit = 0x800;     ///< means the underlying matrix data can be direclty \
accessed +const unsigned int ArrayBit = 0x1000;           ///< means the underlying \
matrix data can be direclty accessed  
 // list of flags that are inherited by default
 const unsigned int HereditaryBits = RowMajorBit
                                   | EvalBeforeNestingBit
                                   | EvalBeforeAssigningBit
-                                  | LargeBit;
+                                  | LargeBit
+                                  | ArrayBit;
 
 // Possible values for the Mode parameter of part() and of extract()
 const unsigned int Upper = UpperTriangularBit;
--- branches/work/eigen2/Eigen/src/Core/util/ForwardDeclarations.h #814311:814312
@@ -50,6 +50,7 @@
 template<int Direction, typename UnaryOp, typename MatrixType> class PartialRedux;
 template<typename MatrixType, unsigned int Mode> class Part;
 template<typename MatrixType, unsigned int Mode> class Extract;
+template<typename Derived, bool HasArrayFlag = int(ei_traits<Derived>::Flags) & \
ArrayBit> class ArrayBase;  
 
 template<typename Scalar> struct ei_scalar_sum_op;
--- branches/work/eigen2/Eigen/src/Core/util/Meta.h #814311:814312
@@ -202,8 +202,8 @@
     ei_must_nest_by_value<T>::ret,
     T,
     typename ei_meta_if<
-      int(ei_traits<T>::Flags) & EvalBeforeNestingBit
-      || (n+1) * int(NumTraits<typename ei_traits<T>::Scalar>::ReadCost) < (n-1) * \
int(T::CoeffReadCost), +      (int(ei_traits<T>::Flags) & EvalBeforeNestingBit)
+      || ((n+1) * int(NumTraits<typename ei_traits<T>::Scalar>::ReadCost) < (n-1) * \
int(T::CoeffReadCost)),  typename ei_eval<T>::type,
       const T&
     >::ret


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic