MCPcopy Create free account
hub / github.com/avaxman/Directional / comparisons

Function comparisons

external/eigen/test/array_cwise.cpp:639–759  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

637}
638
639template<typename ArrayType> void comparisons(const ArrayType& m)
640{
641 using numext::abs;
642 typedef typename ArrayType::Scalar Scalar;
643 typedef typename NumTraits<Scalar>::Real RealScalar;
644
645 Index rows = m.rows();
646 Index cols = m.cols();
647
648 Index r = internal::random<Index>(0, rows-1),
649 c = internal::random<Index>(0, cols-1);
650
651 ArrayType m1 = ArrayType::Random(rows, cols),
652 m2 = ArrayType::Random(rows, cols),
653 m3(rows, cols),
654 m4 = m1;
655
656 m4 = (m4.abs()==Scalar(0)).select(1,m4);
657
658 // use operator overloads with default return type
659
660 VERIFY(((m1 + Scalar(1)) > m1).all());
661 VERIFY(((m1 - Scalar(1)) < m1).all());
662 if (rows*cols>1)
663 {
664 m3 = m1;
665 m3(r,c) += 1;
666 VERIFY(! (m1 < m3).all() );
667 VERIFY(! (m1 > m3).all() );
668 }
669 VERIFY(!(m1 > m2 && m1 < m2).any());
670 VERIFY((m1 <= m2 || m1 >= m2).all());
671
672 // comparisons array to scalar
673 VERIFY( (m1 != (m1(r,c)+1) ).any() );
674 VERIFY( (m1 > (m1(r,c)-1) ).any() );
675 VERIFY( (m1 < (m1(r,c)+1) ).any() );
676 VERIFY( (m1 == m1(r,c) ).any() );
677
678 // comparisons scalar to array
679 VERIFY( ( (m1(r,c)+1) != m1).any() );
680 VERIFY( ( (m1(r,c)-1) < m1).any() );
681 VERIFY( ( (m1(r,c)+1) > m1).any() );
682 VERIFY( ( m1(r,c) == m1).any() );
683
684 // currently, any() / all() are not vectorized, so use VERIFY_IS_CWISE_EQUAL to test vectorized path
685
686 // use typed comparisons, regardless of operator overload behavior
687 typename ArrayType::ConstantReturnType typed_true = ArrayType::Constant(rows, cols, Scalar(1));
688 // (m1 + Scalar(1)) > m1).all()
689 VERIFY_IS_CWISE_EQUAL((m1 + Scalar(1)).cwiseTypedGreater(m1), typed_true);
690 // (m1 - Scalar(1)) < m1).all()
691 VERIFY_IS_CWISE_EQUAL((m1 - Scalar(1)).cwiseTypedLess(m1), typed_true);
692 // (m1 + Scalar(1)) == (m1 + Scalar(1))).all()
693 VERIFY_IS_CWISE_EQUAL((m1 + Scalar(1)).cwiseTypedEqual(m1 + Scalar(1)), typed_true);
694 // (m1 - Scalar(1)) != m1).all()
695 VERIFY_IS_CWISE_EQUAL((m1 - Scalar(1)).cwiseTypedNotEqual(m1), typed_true);
696 // (m1 <= m2 || m1 >= m2).all()

Callers 1

EIGEN_DECLARE_TESTFunction · 0.70

Calls 15

selectMethod · 0.80
cwiseMinMethod · 0.80
cwiseMaxMethod · 0.80
colwiseMethod · 0.80
rowwiseMethod · 0.80
absFunction · 0.70
rowsMethod · 0.45
colsMethod · 0.45
absMethod · 0.45
allMethod · 0.45
anyMethod · 0.45
minCoeffMethod · 0.45

Tested by

no test coverage detected