diff --git a/Eigen/src/Core/CwiseNullaryOp.h b/Eigen/src/Core/CwiseNullaryOp.h index 25041d1b7..97331fa26 100644 --- a/Eigen/src/Core/CwiseNullaryOp.h +++ b/Eigen/src/Core/CwiseNullaryOp.h @@ -240,16 +240,29 @@ DenseBase::Constant(const Scalar& value) * Example: \include DenseBase_LinSpaced_seq.cpp * Output: \verbinclude DenseBase_LinSpaced_seq.out * - * \sa setLinSpaced(const Scalar&,const Scalar&,Index), LinSpaced(Scalar,Scalar,Index), CwiseNullaryOp + * \sa setLinSpaced(Index,const Scalar&,const Scalar&), LinSpaced(Index,Scalar,Scalar), CwiseNullaryOp */ template EIGEN_STRONG_INLINE const typename DenseBase::SequentialLinSpacedReturnType -DenseBase::LinSpaced(Sequential_t, const Scalar& low, const Scalar& high, Index size) +DenseBase::LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return DenseBase::NullaryExpr(size, ei_linspaced_op(low,high,size)); } +/** + * \copydoc DenseBase::LinSpaced(Sequential_t, Index, const Scalar&, const Scalar&) + * Special version for fixed size types which does not require the size parameter. + */ +template +EIGEN_STRONG_INLINE const typename DenseBase::SequentialLinSpacedReturnType +DenseBase::LinSpaced(Sequential_t, const Scalar& low, const Scalar& high) +{ + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) + return DenseBase::NullaryExpr(Derived::SizeAtCompileTime, ei_linspaced_op(low,high,Derived::SizeAtCompileTime)); +} + /** * \brief Sets a linearly space vector. * @@ -260,16 +273,29 @@ DenseBase::LinSpaced(Sequential_t, const Scalar& low, const Scalar& hig * Example: \include DenseBase_LinSpaced.cpp * Output: \verbinclude DenseBase_LinSpaced.out * - * \sa setLinSpaced(const Scalar&,const Scalar&,Index), LinSpaced(Sequential_t,const Scalar&,const Scalar&,Index), CwiseNullaryOp + * \sa setLinSpaced(Index,const Scalar&,const Scalar&), LinSpaced(Sequential_t,Index,const Scalar&,const Scalar&,Index), CwiseNullaryOp */ template EIGEN_STRONG_INLINE const typename DenseBase::RandomAccessLinSpacedReturnType -DenseBase::LinSpaced(const Scalar& low, const Scalar& high, Index size) +DenseBase::LinSpaced(Index size, const Scalar& low, const Scalar& high) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return DenseBase::NullaryExpr(size, ei_linspaced_op(low,high,size)); } +/** + * \copydoc DenseBase::LinSpaced(Index, const Scalar&, const Scalar&) + * Special version for fixed size types which does not require the size parameter. + */ +template +EIGEN_STRONG_INLINE const typename DenseBase::RandomAccessLinSpacedReturnType +DenseBase::LinSpaced(const Scalar& low, const Scalar& high) +{ + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) + return DenseBase::NullaryExpr(Derived::SizeAtCompileTime, ei_linspaced_op(low,high,Derived::SizeAtCompileTime)); +} + /** \returns true if all coefficients in this matrix are approximately equal to \a value, to within precision \a prec */ template bool DenseBase::isApproxToConstant @@ -360,7 +386,7 @@ DenseStorageBase::setConstant(Index rows, Index cols, const Scalar& val * \sa CwiseNullaryOp */ template -EIGEN_STRONG_INLINE Derived& DenseBase::setLinSpaced(const Scalar& low, const Scalar& high, Index size) +EIGEN_STRONG_INLINE Derived& DenseBase::setLinSpaced(Index size, const Scalar& low, const Scalar& high) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return derived() = Derived::NullaryExpr(size, ei_linspaced_op(low,high,size)); diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index 6f5013e2d..c84544ec3 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -398,9 +398,13 @@ template class DenseBase Constant(const Scalar& value); static const SequentialLinSpacedReturnType - LinSpaced(Sequential_t, const Scalar& low, const Scalar& high, Index size); + LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high); static const RandomAccessLinSpacedReturnType - LinSpaced(const Scalar& low, const Scalar& high, Index size); + LinSpaced(Index size, const Scalar& low, const Scalar& high); + static const SequentialLinSpacedReturnType + LinSpaced(Sequential_t, const Scalar& low, const Scalar& high); + static const RandomAccessLinSpacedReturnType + LinSpaced(const Scalar& low, const Scalar& high); template static const CwiseNullaryOp @@ -421,7 +425,8 @@ template class DenseBase void fill(const Scalar& value); Derived& setConstant(const Scalar& value); - Derived& setLinSpaced(const Scalar& low, const Scalar& high, Index size); + Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high); + Derived& setLinSpaced(const Scalar& low, const Scalar& high); Derived& setZero(); Derived& setOnes(); Derived& setRandom(); diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h index 9084905aa..c3a3a92c4 100644 --- a/Eigen/src/Core/Functors.h +++ b/Eigen/src/Core/Functors.h @@ -573,7 +573,7 @@ template struct ei_linspaced_op template EIGEN_STRONG_INLINE const PacketScalar packetOp(Index i, Index = 0) const { return impl.packetOp(i); } // This proxy object handles the actual required temporaries, the different - // implementations (random vs. sequential access) as well as the piping + // implementations (random vs. sequential access) as well as the // correct piping to size 2/4 packet operations. const ei_linspaced_op_impl impl; }; diff --git a/doc/snippets/DenseBase_LinSpaced.cpp b/doc/snippets/DenseBase_LinSpaced.cpp index c8c3e972c..8e54b17fc 100644 --- a/doc/snippets/DenseBase_LinSpaced.cpp +++ b/doc/snippets/DenseBase_LinSpaced.cpp @@ -1,2 +1,2 @@ -cout << VectorXi::LinSpaced(7,10,4).transpose() << endl; -cout << VectorXd::LinSpaced(0.0,1.0,5).transpose() << endl; +cout << VectorXi::LinSpaced(4,7,10).transpose() << endl; +cout << VectorXd::LinSpaced(5,0.0,1.0).transpose() << endl; diff --git a/doc/snippets/DenseBase_LinSpaced_seq.cpp b/doc/snippets/DenseBase_LinSpaced_seq.cpp index 73873c4e9..f55c5085d 100644 --- a/doc/snippets/DenseBase_LinSpaced_seq.cpp +++ b/doc/snippets/DenseBase_LinSpaced_seq.cpp @@ -1,2 +1,2 @@ -cout << VectorXi::LinSpaced(Sequential,7,10,4).transpose() << endl; -cout << VectorXd::LinSpaced(Sequential,0.0,1.0,5).transpose() << endl; +cout << VectorXi::LinSpaced(Sequential,4,7,10).transpose() << endl; +cout << VectorXd::LinSpaced(Sequential,5,0.0,1.0).transpose() << endl; diff --git a/doc/snippets/DenseBase_setLinSpaced.cpp b/doc/snippets/DenseBase_setLinSpaced.cpp index a8ea73407..50871dfcc 100644 --- a/doc/snippets/DenseBase_setLinSpaced.cpp +++ b/doc/snippets/DenseBase_setLinSpaced.cpp @@ -1,3 +1,3 @@ VectorXf v; -v.setLinSpaced(0.5f,1.5f,5).transpose(); +v.setLinSpaced(5,0.5f,1.5f).transpose(); cout << v << endl; diff --git a/test/nullary.cpp b/test/nullary.cpp index c54999580..78d2e9117 100644 --- a/test/nullary.cpp +++ b/test/nullary.cpp @@ -59,7 +59,7 @@ void testVectorType(const VectorType& base) // check whether the result yields what we expect it to do VectorType m(base); - m.setLinSpaced(low,high,size); + m.setLinSpaced(size,low,high); VectorType n(size); for (int i=0; i::epsilon()*10e3 ); // random access version - m = VectorType::LinSpaced(low,high,size); + m = VectorType::LinSpaced(size,low,high); VERIFY( (m-n).norm() < std::numeric_limits::epsilon()*10e3 ); // These guys sometimes fail! This is not good. Any ideas how to fix them!? @@ -76,7 +76,7 @@ void testVectorType(const VectorType& base) //VERIFY( m(0) == low ); // sequential access version - m = VectorType::LinSpaced(Sequential,low,high,size); + m = VectorType::LinSpaced(Sequential,size,low,high); VERIFY( (m-n).norm() < std::numeric_limits::epsilon()*10e3 ); // These guys sometimes fail! This is not good. Any ideas how to fix them!? @@ -86,12 +86,12 @@ void testVectorType(const VectorType& base) // check whether everything works with row and col major vectors Matrix row_vector(size); Matrix col_vector(size); - row_vector.setLinSpaced(low,high,size); - col_vector.setLinSpaced(low,high,size); + row_vector.setLinSpaced(size,low,high); + col_vector.setLinSpaced(size,low,high); VERIFY( row_vector.isApprox(col_vector.transpose(), NumTraits::epsilon())); Matrix size_changer(size+50); - size_changer.setLinSpaced(low,high,size); + size_changer.setLinSpaced(size,low,high); VERIFY( size_changer.size() == size ); }