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

(-)a/Eigen/src/Core/Array.h (-2 / +16 lines)
Lines 69-84 class Array Link Here
69
      * the usage of 'using'. This should be done only for operator=.
69
      * the usage of 'using'. This should be done only for operator=.
70
      */
70
      */
71
    template<typename OtherDerived>
71
    template<typename OtherDerived>
72
    EIGEN_DEVICE_FUNC
72
    EIGEN_DEVICE_FUNC
73
    EIGEN_STRONG_INLINE Array& operator=(const EigenBase<OtherDerived> &other)
73
    EIGEN_STRONG_INLINE Array& operator=(const EigenBase<OtherDerived> &other)
74
    {
74
    {
75
      return Base::operator=(other);
75
      return Base::operator=(other);
76
    }
76
    }
77
    
78
    /** Set all the entries to \a value.
79
      * \sa DenseBase::setConstant(), DenseBase::fill()
80
      */
81
    /* This overload is needed because the usage of
82
      *   using Base::operator=;
83
      * fails on MSVC. Since the code below is working with GCC and MSVC, we skipped
84
      * the usage of 'using'. This should be done only for operator=.
85
      */
86
    EIGEN_DEVICE_FUNC
87
    EIGEN_STRONG_INLINE Array& operator=(const Scalar &value)
88
    {
89
      Base::setConstant(value);
90
      return *this;
91
    }
77
92
78
    /** Copies the value of the expression \a other into \c *this with automatic resizing.
93
    /** Copies the value of the expression \a other into \c *this with automatic resizing.
79
      *
94
      *
80
      * *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized),
95
      * *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized),
81
      * it will be initialized.
96
      * it will be initialized.
82
      *
97
      *
83
      * Note that copying a row-vector into a vector (and conversely) is allowed.
98
      * Note that copying a row-vector into a vector (and conversely) is allowed.
84
      * The resizing, if any, is then done in the appropriate way so that row-vectors
99
      * The resizing, if any, is then done in the appropriate way so that row-vectors
Lines 94-110 class Array Link Here
94
    /** This is a special case of the templated operator=. Its purpose is to
109
    /** This is a special case of the templated operator=. Its purpose is to
95
      * prevent a default operator= from hiding the templated operator=.
110
      * prevent a default operator= from hiding the templated operator=.
96
      */
111
      */
97
    EIGEN_DEVICE_FUNC
112
    EIGEN_DEVICE_FUNC
98
    EIGEN_STRONG_INLINE Array& operator=(const Array& other)
113
    EIGEN_STRONG_INLINE Array& operator=(const Array& other)
99
    {
114
    {
100
      return Base::_set(other);
115
      return Base::_set(other);
101
    }
116
    }
102
117
    
103
    /** Default constructor.
118
    /** Default constructor.
104
      *
119
      *
105
      * For fixed-size matrices, does nothing.
120
      * For fixed-size matrices, does nothing.
106
      *
121
      *
107
      * For dynamic-size matrices, creates an empty matrix of size 0. Does not allocate any array. Such a matrix
122
      * For dynamic-size matrices, creates an empty matrix of size 0. Does not allocate any array. Such a matrix
108
      * is called a null matrix. This constructor is the unique way to create null matrices: resizing
123
      * is called a null matrix. This constructor is the unique way to create null matrices: resizing
109
      * a matrix to 0 is not supported.
124
      * a matrix to 0 is not supported.
110
      *
125
      *
Lines 139-155 class Array Link Here
139
    }
154
    }
140
    Array& operator=(Array&& other)
155
    Array& operator=(Array&& other)
141
    {
156
    {
142
      other.swap(*this);
157
      other.swap(*this);
143
      return *this;
158
      return *this;
144
    }
159
    }
145
#endif
160
#endif
146
161
147
148
    #ifndef EIGEN_PARSED_BY_DOXYGEN
162
    #ifndef EIGEN_PARSED_BY_DOXYGEN
149
    template<typename T>
163
    template<typename T>
150
    EIGEN_DEVICE_FUNC
164
    EIGEN_DEVICE_FUNC
151
    EIGEN_STRONG_INLINE explicit Array(const T& x)
165
    EIGEN_STRONG_INLINE explicit Array(const T& x)
152
    {
166
    {
153
      Base::_check_template_params();
167
      Base::_check_template_params();
154
      Base::template _init1<T>(x);
168
      Base::template _init1<T>(x);
155
    }
169
    }
(-)a/Eigen/src/Core/ArrayBase.h (+6 lines)
Lines 118-133 template<typename Derived> class ArrayBa Link Here
118
    /** Special case of the template operator=, in order to prevent the compiler
118
    /** Special case of the template operator=, in order to prevent the compiler
119
      * from generating a default operator= (issue hit with g++ 4.1)
119
      * from generating a default operator= (issue hit with g++ 4.1)
120
      */
120
      */
121
    EIGEN_DEVICE_FUNC
121
    EIGEN_DEVICE_FUNC
122
    Derived& operator=(const ArrayBase& other)
122
    Derived& operator=(const ArrayBase& other)
123
    {
123
    {
124
      return internal::assign_selector<Derived,Derived>::run(derived(), other.derived());
124
      return internal::assign_selector<Derived,Derived>::run(derived(), other.derived());
125
    }
125
    }
126
    
127
    /** Set all the entries to \a value.
128
      * \sa DenseBase::setConstant(), DenseBase::fill() */
129
    EIGEN_DEVICE_FUNC
130
    Derived& operator=(const Scalar &value)
131
    { Base::setConstant(value); return derived(); }
126
132
127
    EIGEN_DEVICE_FUNC
133
    EIGEN_DEVICE_FUNC
128
    Derived& operator+=(const Scalar& scalar);
134
    Derived& operator+=(const Scalar& scalar);
129
    EIGEN_DEVICE_FUNC
135
    EIGEN_DEVICE_FUNC
130
    Derived& operator-=(const Scalar& scalar);
136
    Derived& operator-=(const Scalar& scalar);
131
137
132
    template<typename OtherDerived>
138
    template<typename OtherDerived>
133
    EIGEN_DEVICE_FUNC
139
    EIGEN_DEVICE_FUNC
(-)a/Eigen/src/Core/PlainObjectBase.h (-1 / +35 lines)
Lines 699-756 class PlainObjectBase : public internal: Link Here
699
                                                                  && (internal::is_same<T1,Index>::value)
699
                                                                  && (internal::is_same<T1,Index>::value)
700
                                                                  && Base::SizeAtCompileTime==2,T1>::type* = 0)
700
                                                                  && Base::SizeAtCompileTime==2,T1>::type* = 0)
701
    {
701
    {
702
      EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
702
      EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
703
      m_storage.data()[0] = Scalar(val0);
703
      m_storage.data()[0] = Scalar(val0);
704
      m_storage.data()[1] = Scalar(val1);
704
      m_storage.data()[1] = Scalar(val1);
705
    }
705
    }
706
706
707
    // The argument is convertible to the Index type and we either have a non 1x1 Matrix, or a dynamic-sized Array,
708
    // then the argument is meant to be the size of the object.
707
    template<typename T>
709
    template<typename T>
708
    EIGEN_DEVICE_FUNC
710
    EIGEN_DEVICE_FUNC
709
    EIGEN_STRONG_INLINE void _init1(Index size, typename internal::enable_if<Base::SizeAtCompileTime!=1 || !internal::is_convertible<T, Scalar>::value,T>::type* = 0)
711
    EIGEN_STRONG_INLINE void _init1(Index size, typename internal::enable_if<    (Base::SizeAtCompileTime!=1 || !internal::is_convertible<T, Scalar>::value)
712
                                                                              && ((!internal::is_same<typename internal::traits<Derived>::XprKind,ArrayXpr>::value || Base::SizeAtCompileTime==Dynamic)),T>::type* = 0)
710
    {
713
    {
711
      // NOTE MSVC 2008 complains if we directly put bool(NumTraits<T>::IsInteger) as the EIGEN_STATIC_ASSERT argument.
714
      // NOTE MSVC 2008 complains if we directly put bool(NumTraits<T>::IsInteger) as the EIGEN_STATIC_ASSERT argument.
712
      const bool is_integer = NumTraits<T>::IsInteger;
715
      const bool is_integer = NumTraits<T>::IsInteger;
713
      EIGEN_STATIC_ASSERT(is_integer,
716
      EIGEN_STATIC_ASSERT(is_integer,
714
                          FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
717
                          FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
715
      resize(size);
718
      resize(size);
716
    }
719
    }
720
    
721
    // We have a 1x1 matrix/array => the argument is interpreted as the value of the unique coefficient (case where scalar type can be implicitely converted)
717
    template<typename T>
722
    template<typename T>
718
    EIGEN_DEVICE_FUNC
723
    EIGEN_DEVICE_FUNC
719
    EIGEN_STRONG_INLINE void _init1(const Scalar& val0, typename internal::enable_if<Base::SizeAtCompileTime==1 && internal::is_convertible<T, Scalar>::value,T>::type* = 0)
724
    EIGEN_STRONG_INLINE void _init1(const Scalar& val0, typename internal::enable_if<Base::SizeAtCompileTime==1 && internal::is_convertible<T, Scalar>::value,T>::type* = 0)
720
    {
725
    {
721
      EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
726
      EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
722
      m_storage.data()[0] = val0;
727
      m_storage.data()[0] = val0;
723
    }
728
    }
724
    
729
    
730
    // We have a 1x1 matrix/array => the argument is interpreted as the value of the unique coefficient (case where scalar type match the index type)
725
    template<typename T>
731
    template<typename T>
726
    EIGEN_DEVICE_FUNC
732
    EIGEN_DEVICE_FUNC
727
    EIGEN_STRONG_INLINE void _init1(const Index& val0,
733
    EIGEN_STRONG_INLINE void _init1(const Index& val0,
728
                                    typename internal::enable_if<    (!internal::is_same<Index,Scalar>::value)
734
                                    typename internal::enable_if<    (!internal::is_same<Index,Scalar>::value)
729
                                                                  && (internal::is_same<Index,T>::value)
735
                                                                  && (internal::is_same<Index,T>::value)
730
                                                                  && Base::SizeAtCompileTime==1
736
                                                                  && Base::SizeAtCompileTime==1
731
                                                                  && internal::is_convertible<T, Scalar>::value,T*>::type* = 0)
737
                                                                  && internal::is_convertible<T, Scalar>::value,T*>::type* = 0)
732
    {
738
    {
733
      EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
739
      EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
734
      m_storage.data()[0] = Scalar(val0);
740
      m_storage.data()[0] = Scalar(val0);
735
    }
741
    }
736
742
743
    // Initialize a fixed size matrix from a pointer to raw data
737
    template<typename T>
744
    template<typename T>
738
    EIGEN_DEVICE_FUNC
745
    EIGEN_DEVICE_FUNC
739
    EIGEN_STRONG_INLINE void _init1(const Scalar* data){
746
    EIGEN_STRONG_INLINE void _init1(const Scalar* data){
740
      this->_set_noalias(ConstMapType(data));
747
      this->_set_noalias(ConstMapType(data));
741
    }
748
    }
742
749
750
    // Initialize an arbitrary matrix from a dense expression
743
    template<typename T, typename OtherDerived>
751
    template<typename T, typename OtherDerived>
744
    EIGEN_DEVICE_FUNC
752
    EIGEN_DEVICE_FUNC
745
    EIGEN_STRONG_INLINE void _init1(const DenseBase<OtherDerived>& other){
753
    EIGEN_STRONG_INLINE void _init1(const DenseBase<OtherDerived>& other){
746
      this->_set_noalias(other);
754
      this->_set_noalias(other);
747
    }
755
    }
748
756
757
    // Initialize an arbitrary matrix from a generic Eigen expression
749
    template<typename T, typename OtherDerived>
758
    template<typename T, typename OtherDerived>
750
    EIGEN_DEVICE_FUNC
759
    EIGEN_DEVICE_FUNC
751
    EIGEN_STRONG_INLINE void _init1(const EigenBase<OtherDerived>& other){
760
    EIGEN_STRONG_INLINE void _init1(const EigenBase<OtherDerived>& other){
752
      this->derived() = other;
761
      this->derived() = other;
753
    }
762
    }
754
763
755
    template<typename T, typename OtherDerived>
764
    template<typename T, typename OtherDerived>
756
    EIGEN_DEVICE_FUNC
765
    EIGEN_DEVICE_FUNC
Lines 761-776 class PlainObjectBase : public internal: Link Here
761
    }
770
    }
762
771
763
    template<typename T, typename OtherDerived, int ColsAtCompileTime>
772
    template<typename T, typename OtherDerived, int ColsAtCompileTime>
764
    EIGEN_DEVICE_FUNC
773
    EIGEN_DEVICE_FUNC
765
    EIGEN_STRONG_INLINE void _init1(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
774
    EIGEN_STRONG_INLINE void _init1(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
766
    {
775
    {
767
      this->derived() = r;
776
      this->derived() = r;
768
    }
777
    }
778
    
779
    // For fixed -size arrays:
780
    template<typename T>
781
    EIGEN_DEVICE_FUNC
782
    EIGEN_STRONG_INLINE void _init1(const Scalar& val0,
783
                                    typename internal::enable_if<    Base::SizeAtCompileTime!=Dynamic
784
                                                                  && Base::SizeAtCompileTime!=1
785
                                                                  && internal::is_convertible<T, Scalar>::value
786
                                                                  && internal::is_same<typename internal::traits<Derived>::XprKind,ArrayXpr>::value,T>::type* = 0)
787
    {
788
      Base::setConstant(val0);
789
    }
790
    
791
    template<typename T>
792
    EIGEN_DEVICE_FUNC
793
    EIGEN_STRONG_INLINE void _init1(const Index& val0,
794
                                    typename internal::enable_if<    (!internal::is_same<Index,Scalar>::value)
795
                                                                  && (internal::is_same<Index,T>::value)
796
                                                                  && Base::SizeAtCompileTime!=Dynamic
797
                                                                  && Base::SizeAtCompileTime!=1
798
                                                                  && internal::is_convertible<T, Scalar>::value
799
                                                                  && internal::is_same<typename internal::traits<Derived>::XprKind,ArrayXpr>::value,T*>::type* = 0)
800
    {
801
      Base::setConstant(val0);
802
    }
769
803
770
    template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers>
804
    template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers>
771
    friend struct internal::matrix_swap_impl;
805
    friend struct internal::matrix_swap_impl;
772
806
773
    /** \internal generic implementation of swap for dense storage since for dynamic-sized matrices of same type it is enough to swap the
807
    /** \internal generic implementation of swap for dense storage since for dynamic-sized matrices of same type it is enough to swap the
774
      * data pointers.
808
      * data pointers.
775
      */
809
      */
776
    template<typename OtherDerived>
810
    template<typename OtherDerived>
(-)a/test/array.cpp (+22 lines)
Lines 76-91 template<typename ArrayType> void array( Link Here
76
  m3 = m1;
76
  m3 = m1;
77
  VERIFY_IS_APPROX(m3.colwise() += cv1, m1.colwise() + cv1);
77
  VERIFY_IS_APPROX(m3.colwise() += cv1, m1.colwise() + cv1);
78
  m3 = m1;
78
  m3 = m1;
79
  VERIFY_IS_APPROX(m3.colwise() -= cv1, m1.colwise() - cv1);
79
  VERIFY_IS_APPROX(m3.colwise() -= cv1, m1.colwise() - cv1);
80
  m3 = m1;
80
  m3 = m1;
81
  VERIFY_IS_APPROX(m3.rowwise() += rv1, m1.rowwise() + rv1);
81
  VERIFY_IS_APPROX(m3.rowwise() += rv1, m1.rowwise() + rv1);
82
  m3 = m1;
82
  m3 = m1;
83
  VERIFY_IS_APPROX(m3.rowwise() -= rv1, m1.rowwise() - rv1);
83
  VERIFY_IS_APPROX(m3.rowwise() -= rv1, m1.rowwise() - rv1);
84
  
85
  // Conversion from scalar
86
  VERIFY_IS_APPROX((m3 = s1), ArrayType::Constant(rows,cols,s1));
87
  VERIFY_IS_APPROX((m3 = 1),  ArrayType::Constant(rows,cols,1));
88
  VERIFY_IS_APPROX((m3.topLeftCorner(rows,cols) = 1),  ArrayType::Constant(rows,cols,1));
89
  typedef Array<Scalar,
90
                ArrayType::RowsAtCompileTime==Dynamic?2:ArrayType::RowsAtCompileTime,
91
                ArrayType::ColsAtCompileTime==Dynamic?2:ArrayType::ColsAtCompileTime,
92
                ArrayType::Options> FixedArrayType;
93
  FixedArrayType f1(s1);
94
  VERIFY_IS_APPROX(f1, FixedArrayType::Constant(s1));
95
  FixedArrayType f2(numext::real(s1));
96
  VERIFY_IS_APPROX(f2, FixedArrayType::Constant(numext::real(s1)));
97
  FixedArrayType f3((int)100*numext::real(s1));
98
  VERIFY_IS_APPROX(f3, FixedArrayType::Constant((int)100*numext::real(s1)));
99
  
100
  // Check possible conflicts with 1D ctor
101
  typedef Array<Scalar, Dynamic, 1> OneDArrayType;
102
  OneDArrayType o1(rows);
103
  VERIFY(o1.size()==rows);
104
  OneDArrayType o4((int)rows);
105
  VERIFY(o4.size()==rows);
84
}
106
}
85
107
86
template<typename ArrayType> void comparisons(const ArrayType& m)
108
template<typename ArrayType> void comparisons(const ArrayType& m)
87
{
109
{
88
  using std::abs;
110
  using std::abs;
89
  typedef typename ArrayType::Index Index;
111
  typedef typename ArrayType::Index Index;
90
  typedef typename ArrayType::Scalar Scalar;
112
  typedef typename ArrayType::Scalar Scalar;
91
  typedef typename NumTraits<Scalar>::Real RealScalar;
113
  typedef typename NumTraits<Scalar>::Real RealScalar;

Return to bug 100