mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 02:33:59 +08:00
Renamed shift_left/shift_right to shiftLeft/shiftRight.
For naming consistency. Also moved to ArrayCwiseUnaryOps, and added test.
This commit is contained in:
parent
2cc6ee0d2e
commit
fc9d352432
@ -497,6 +497,45 @@ ceil() const
|
||||
return CeilReturnType(derived());
|
||||
}
|
||||
|
||||
template<int N> struct ShiftRightXpr {
|
||||
typedef CwiseUnaryOp<internal::scalar_shift_right_op<Scalar, N>, const Derived> Type;
|
||||
};
|
||||
|
||||
/** \returns an expression of \c *this with the \a Scalar type arithmetically
|
||||
* shifted right by \a N bit positions.
|
||||
*
|
||||
* The template parameter \a N specifies the number of bit positions to shift.
|
||||
*
|
||||
* \sa shiftLeft()
|
||||
*/
|
||||
template<int N>
|
||||
EIGEN_DEVICE_FUNC
|
||||
typename ShiftRightXpr<N>::Type
|
||||
shiftRight() const
|
||||
{
|
||||
return typename ShiftRightXpr<N>::Type(derived());
|
||||
}
|
||||
|
||||
|
||||
template<int N> struct ShiftLeftXpr {
|
||||
typedef CwiseUnaryOp<internal::scalar_shift_left_op<Scalar, N>, const Derived> Type;
|
||||
};
|
||||
|
||||
/** \returns an expression of \c *this with the \a Scalar type logically
|
||||
* shifted left by \a N bit positions.
|
||||
*
|
||||
* The template parameter \a N specifies the number of bit positions to shift.
|
||||
*
|
||||
* \sa shiftRight()
|
||||
*/
|
||||
template<int N>
|
||||
EIGEN_DEVICE_FUNC
|
||||
typename ShiftLeftXpr<N>::Type
|
||||
shiftLeft() const
|
||||
{
|
||||
return typename ShiftLeftXpr<N>::Type(derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise isnan of *this.
|
||||
*
|
||||
* Example: \include Cwise_isNaN.cpp
|
||||
|
@ -64,49 +64,6 @@ cast() const
|
||||
return typename CastXpr<NewType>::Type(derived());
|
||||
}
|
||||
|
||||
template<int N> struct ShiftRightXpr {
|
||||
typedef CwiseUnaryOp<internal::scalar_shift_right_op<Scalar, N>, const Derived> Type;
|
||||
};
|
||||
|
||||
/// \returns an expression of \c *this with the \a Scalar type arithmetically
|
||||
/// shifted right by \a N bit positions.
|
||||
///
|
||||
/// The template parameter \a N specifies the number of bit positions to shift.
|
||||
///
|
||||
EIGEN_DOC_UNARY_ADDONS(cast,conversion function)
|
||||
///
|
||||
/// \sa class CwiseUnaryOp
|
||||
///
|
||||
template<int N>
|
||||
EIGEN_DEVICE_FUNC
|
||||
typename ShiftRightXpr<N>::Type
|
||||
shift_right() const
|
||||
{
|
||||
return typename ShiftRightXpr<N>::Type(derived());
|
||||
}
|
||||
|
||||
|
||||
template<int N> struct ShiftLeftXpr {
|
||||
typedef CwiseUnaryOp<internal::scalar_shift_left_op<Scalar, N>, const Derived> Type;
|
||||
};
|
||||
|
||||
/// \returns an expression of \c *this with the \a Scalar type logically
|
||||
/// shifted left by \a N bit positions.
|
||||
///
|
||||
/// The template parameter \a N specifies the number of bit positions to shift.
|
||||
///
|
||||
EIGEN_DOC_UNARY_ADDONS(cast,conversion function)
|
||||
///
|
||||
/// \sa class CwiseUnaryOp
|
||||
///
|
||||
template<int N>
|
||||
EIGEN_DEVICE_FUNC
|
||||
typename ShiftLeftXpr<N>::Type
|
||||
shift_left() const
|
||||
{
|
||||
return typename ShiftLeftXpr<N>::Type(derived());
|
||||
}
|
||||
|
||||
/// \returns an expression of the complex conjugate of \c *this.
|
||||
///
|
||||
EIGEN_DOC_UNARY_ADDONS(conjugate,complex conjugate)
|
||||
|
@ -626,6 +626,41 @@ template<typename ArrayType> void min_max(const ArrayType& m)
|
||||
}
|
||||
}
|
||||
|
||||
template<int N>
|
||||
struct shift_left {
|
||||
template<typename Scalar>
|
||||
Scalar operator()(const Scalar& v) const {
|
||||
return v << N;
|
||||
}
|
||||
};
|
||||
|
||||
template<int N>
|
||||
struct arithmetic_shift_right {
|
||||
template<typename Scalar>
|
||||
Scalar operator()(const Scalar& v) const {
|
||||
return v >> N;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename ArrayType> void array_integer(const ArrayType& m)
|
||||
{
|
||||
Index rows = m.rows();
|
||||
Index cols = m.cols();
|
||||
|
||||
ArrayType m1 = ArrayType::Random(rows, cols),
|
||||
m2(rows, cols);
|
||||
|
||||
m2 = m1.template shiftLeft<2>();
|
||||
VERIFY( (m2 == m1.unaryExpr(shift_left<2>())).all() );
|
||||
m2 = m1.template shiftLeft<9>();
|
||||
VERIFY( (m2 == m1.unaryExpr(shift_left<9>())).all() );
|
||||
|
||||
m2 = m1.template shiftRight<2>();
|
||||
VERIFY( (m2 == m1.unaryExpr(arithmetic_shift_right<2>())).all() );
|
||||
m2 = m1.template shiftRight<9>();
|
||||
VERIFY( (m2 == m1.unaryExpr(arithmetic_shift_right<9>())).all() );
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(array_cwise)
|
||||
{
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
@ -636,6 +671,8 @@ EIGEN_DECLARE_TEST(array_cwise)
|
||||
CALL_SUBTEST_5( array(ArrayXXf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
|
||||
CALL_SUBTEST_6( array(ArrayXXi(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
|
||||
CALL_SUBTEST_6( array(Array<Index,Dynamic,Dynamic>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
|
||||
CALL_SUBTEST_6( array_integer(ArrayXXi(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
|
||||
CALL_SUBTEST_6( array_integer(Array<Index,Dynamic,Dynamic>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
|
||||
}
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
CALL_SUBTEST_1( comparisons(Array<float, 1, 1>()) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user