void test_plus_double_5() { // matrix Array<double> m1( sizeLarge, sizeLarge ); for (double i = 0; i < m1.GetDescriptor().GetDim( 0 ); i++) { for (double j = 0; j < m1.GetDescriptor().GetDim( 1 ); j++) m1(i,j) = -1; } Array<double> m2( sizeLarge, sizeLarge ); for (double i = 0; i < m2.GetDescriptor().GetDim( 0 ); i++) { for (double j = 0; j < m2.GetDescriptor().GetDim( 1 ); j++) m2(i,j) = 1; } Array<double> m3( sizeLarge, sizeLarge ); for (double i = 0; i < m3.GetDescriptor().GetDim( 0 ); i++) { for (double j = 0; j < m3.GetDescriptor().GetDim( 1 ); j++) m3(i,j) = 5; } Array<double> m4( sizeLarge, sizeLarge ); m3 = m1 + m2; TEST_CALL( m3, m4, BOOST_CURRENT_FUNCTION ); }
template<typename MatrixType> void selfadjoint(const MatrixType& m) { typedef typename MatrixType::Index Index; typedef typename MatrixType::Scalar Scalar; Index rows = m.rows(); Index cols = m.cols(); MatrixType m1 = MatrixType::Random(rows, cols), m2 = MatrixType::Random(rows, cols), m3(rows, cols), m4(rows, cols); m1.diagonal() = m1.diagonal().real().template cast<Scalar>(); // check selfadjoint to dense m3 = m1.template selfadjointView<Upper>(); VERIFY_IS_APPROX(MatrixType(m3.template triangularView<Upper>()), MatrixType(m1.template triangularView<Upper>())); VERIFY_IS_APPROX(m3, m3.adjoint()); m3 = m1.template selfadjointView<Lower>(); VERIFY_IS_APPROX(MatrixType(m3.template triangularView<Lower>()), MatrixType(m1.template triangularView<Lower>())); VERIFY_IS_APPROX(m3, m3.adjoint()); m3 = m1.template selfadjointView<Upper>(); m4 = m2; m4 += m1.template selfadjointView<Upper>(); VERIFY_IS_APPROX(m4, m2+m3); m3 = m1.template selfadjointView<Lower>(); m4 = m2; m4 -= m1.template selfadjointView<Lower>(); VERIFY_IS_APPROX(m4, m2-m3); }
void test_plus_float_4() { // matrix Array<float> m1( sizeLarge, sizeLarge ); for (int i = 0; i < m1.GetDescriptor().GetDim( 0 ); i++) { for (int j = 0; j < m1.GetDescriptor().GetDim( 1 ); j++) m1(i,j) = -1.0; } Array<float> m2( sizeLarge, sizeLarge ); for (int i = 0; i < m2.GetDescriptor().GetDim( 0 ); i++) { for (int j = 0; j < m2.GetDescriptor().GetDim( 1 ); j++) m2(i,j) = 1.0; } Array<float> m3( sizeLarge, sizeLarge ); for (int i = 0; i < m3.GetDescriptor().GetDim( 0 ); i++) { for (int j = 0; j < m3.GetDescriptor().GetDim( 1 ); j++) m3(i,j) = 5.0; } Array<float> m4( sizeLarge, sizeLarge ); m3 = m1 + m2; TEST_CALL( m3, m4, BOOST_CURRENT_FUNCTION ); }
void test_plus_double_3() { Array<double> m1( sizeSmall, sizeSmall ); for (int i = 0; i < m1.GetDescriptor().GetDim( 0 ); i++) { for (int j = 0; j < m1.GetDescriptor().GetDim( 1 ); j++) m1(i,j) = -1.0; } Array<double> m2( sizeSmall, sizeSmall ); for (int i = 0; i < m2.GetDescriptor().GetDim( 0 ); i++) { for (int j = 0; j < m2.GetDescriptor().GetDim( 1 ); j++) m2(i,j) = 1.0; } Array<double> m3( sizeSmall, sizeSmall ); for (int i = 0; i < m3.GetDescriptor().GetDim( 0 ); i++) { for (int j = 0; j < m3.GetDescriptor().GetDim( 1 ); j++) m3(i,j) = 5.0; } Array<double> m4( sizeSmall, sizeSmall ); m3 = m1 + m2; TEST_CALL( m3, m4, BOOST_CURRENT_FUNCTION ); }
TEST(Matrix, shouldCompare) { Matrix m1(1,1,1); Matrix m2(1,1,1); Matrix m3(2,1,1); Matrix m4(1,2,1); Matrix m5(1,1,2); CHECK(m1 == m1); CHECK(m1 == m2); CHECK(m2 == m1); CHECK(!(m1 == m3)); CHECK(!(m1 == m4)); CHECK(!(m5 == m1)); CHECK(m5 != m1); float v6[] = { 1, 1, 1, 1 }; Matrix m6(2,2); m6.setAll(v6); float v7[] = { 1, 1, 1, 1 }; Matrix m7(2,2); m7.setAll(v7); float v8[] = { 1, 1, 1, 2 }; Matrix m8(2,2); m8.setAll(v8); CHECK(m7 == m6); CHECK(!(m8 == m6)); CHECK(m6 != m8); CHECK(m1 != m6); CHECK(m6 != m1); }
int main() { // --- get a lot of info from the user --- int n = cwin.get_int( "Dude, I need an int:" ); double x = cwin.get_double( "Dude, I need an double:" ); string stuff = cwin.get_string( "Dude, I need a string:" ); Point p = cwin.get_mouse( "Dude, click the mouse somewhere:" ); // --- set offset double dx = 0.0; double dy = -1.0; // --- create messages for each input --- Message m1( p, "You clicked here." ); p.move( dx, dy ); Message m2( p, "You typed: \"" + stuff + "\"" ); p.move( dx, dy ); Message m3( p, n ); p.move( dx, dy ); Message m4( p, x ); // --- display in window --- cwin << m1 << m2 << m3 << m4 ; return 0; }
int _tmain(int argc, _TCHAR* argv[]) { //Create Matrices of different types and print them cv::Mat m1(4, 5, CV_8UC1, cv::Scalar(23)); printMat1D(m1); cv::Mat m2(3, 2, CV_8SC1, cv::Scalar(-27)); printMat1D(m2); cv::Mat m3(5, 3, CV_16UC1, cv::Scalar(1939)); printMat1D(m3); cv::Mat m4(2, 4, CV_16SC1, cv::Scalar(-1961)); printMat1D(m4); cv::Mat m5(5, 3, CV_32SC1, cv::Scalar(23985)); printMat1D(m5); cv::Mat m6(2, 4, CV_32FC1, cv::Scalar(2011.02)); printMat1D(m6); cv::Mat m7(2, 4, CV_64FC1, cv::Scalar(242012.36)); printMat1D(m7); std::getchar(); return 0; }
int main(int argc, char **argv) { C m1(14); A *mat = new B<C>(m1); assert( mat->rank() == CRank ) ; DMat<int> m2(6); A * mat2 = new B< DMat<int> >(m2); assert( mat2->rank() == DMatIntRank ) ; int m3(4); A * mat3 = new B<int>(m3); assert( intRank == mat3->rank() ); DMat<double> m4(6.0); A * mat4 = new B< DMat<double> >(m4); assert( mat4->rank() == DMatRank ) ; double m5(7.0); A* mat5 = new B<double>(m5); assert(mat5->rank()==genericRank); int d1 = mat->det(); int d2 = mat2->det(); int d3 = mat3->det(); int d4 = mat4->det(); return 0; }
void testDet() { double m1[9] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 }; CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, Open3DMotion::Matrix3x3::Det(m1), 1E-12); Open3DMotion::Matrix3x3 m2(m1); CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, m2.Det(), 1E-12); double m3[9] = { 9,-1,23, -20,-9, 0, 18, 7, 3 }; CPPUNIT_ASSERT_DOUBLES_EQUAL(203.0, Open3DMotion::Matrix3x3::Det(m3), 1E-12); Open3DMotion::Matrix3x3 m4(m3); CPPUNIT_ASSERT_DOUBLES_EQUAL(203.0, m4.Det(), 1E-12); }
void test_plus_complex_5() { // matrix Array<Complex> m1( sizeLarge, sizeLarge ); for (int i = 0; i < m1.GetDescriptor().GetDim( 0 ); i++) { for (int j = 0; j < m1.GetDescriptor().GetDim( 1 ); j++) m1(i,j) = Complex(-1,-1); } Array<Complex> m2( sizeLarge, sizeLarge ); for (int i = 0; i < m1.GetDescriptor().GetDim( 0 ); i++) { for (int j = 0; j < m1.GetDescriptor().GetDim( 1 ); j++) m2(i,j) = Complex(1,1); } Array<Complex> m3( sizeLarge, sizeLarge ); for (int i = 0; i < m1.GetDescriptor().GetDim( 0 ); i++) { for (int j = 0; j < m1.GetDescriptor().GetDim( 1 ); j++) m3(i,j) = Complex(5,5); } Array<Complex> m4( sizeLarge, sizeLarge ); m3 = m1 + m2; TEST_CALL( m3, m4, BOOST_CURRENT_FUNCTION ); }
void test_plus_complex_3() { Array<Complex> m1( sizeSmall, sizeSmall ); for (int i = 0; i < m1.GetDescriptor().GetDim( 0 ); i++) { for (int j = 0; j < m1.GetDescriptor().GetDim( 1 ); j++) m1(i,j) = Complex(-1,-1); } std::complex <double> a = 1; Array<Complex> m2( sizeSmall, sizeSmall ); for (int i = 0; i < m2.GetDescriptor().GetDim( 0 ); i++) { for (int j = 0; j < m2.GetDescriptor().GetDim( 1 ); j++) m2(i,j) = Complex(1,1); } Array<Complex> m3( sizeSmall, sizeSmall ); for (int i = 0; i < m3.GetDescriptor().GetDim( 0 ); i++) { for (int j = 0; j < m3.GetDescriptor().GetDim( 1 ); j++) m3(i,j) = Complex(5,5); } Array<Complex> m4( sizeSmall, sizeSmall ); m3 = m1 + m2; TEST_CALL( m3, m4, BOOST_CURRENT_FUNCTION ); }
void test_dynamic_handler_map() { // Example with enum HandlerMap<MyEnum, std::function<void(int, double)>> m1; m1 (MyEnum::Handler1, &MyDynamicHandler1::handler1) (MyEnum::Handler2, &MyDynamicHandler1::handler2); m1.call(MyEnum::Handler1, 1, 1.0); m1.call(MyEnum::Handler2, 2, 2.0); // Example with enum class HandlerMap<MyEnumClass, std::function<void(int, std::string&)>> m2; m2 (MyEnumClass::HandlerClass1, &MyDynamicHandler2::handler1) (MyEnumClass::HandlerClass2, &MyDynamicHandler2::handler2); std::string s1("atatat1"); std::string s2("atatat2"); m2.call(MyEnumClass::HandlerClass1, 1, std::ref(s1)); m2.call(MyEnumClass::HandlerClass2, 2, std::ref(s2)); try{ // exception should be thrown, no handler for such key m2.call(MyEnumClass::HandlerClass3, 2, std::ref(s2)); } catch (const std::exception& e){ std::cerr << e.what() << '\n'; } // Example with enum int, nullptr handler and return params HandlerMap<int, std::function<int(int, int)>> m3; m3 (0, &MyDynamicHandler3::handler1) (1, &MyDynamicHandler3::handler2) (2, nullptr); int i1 = m3.call(0, 3, 2); int i2 = m3.call(1, 3, 2); // default value returned int i3 = m3.call(2, 3, 2); std::cout << "i1 = " << i1 << '\n'; std::cout << "i2 = " << i2 << '\n'; std::cout << "i3 = " << i3 << '\n'; // Example with non-static members MyDynamicHandler4 my_handler1(10); HandlerMap<int, std::function<void(MyDynamicHandler4&, int)>> m4; m4 (0, &MyDynamicHandler4::handler1) (1, &MyDynamicHandler4::handler2); m4.call(0, my_handler1, 10); m4.call(1, my_handler1, 20); // Example with calling from within the class MyDynamicHandler5 my_handler2(5); my_handler2.call(); }
void RectangleHandler::initRectangle(const Eigen::VectorXd& Sw, double lambda, const Eigen::VectorXd& z, Eigen::VectorXd& shapeParams, Eigen::VectorXd& F) { //Get the points Eigen::Vector3d m1(z[0], z[1], 1); Eigen::Vector3d m2(z[2], z[3], 1); Eigen::Vector3d m3(z[4], z[5], 1); Eigen::Vector3d m4(z[6], z[7], 1); Eigen::Vector3d Ct(Sw[0], Sw[1], Sw[2]); Eigen::Quaterniond Cq(Sw[3], Sw[4], Sw[5], Sw[6]); //compute normals double c2 = (m1.cross(m3).transpose() * m4)[0] / (m2.cross(m3).transpose() * m4)[0]; double c3 = (m1.cross(m3).transpose() * m2)[0] / (m4.cross(m3).transpose() * m2)[0]; Eigen::Vector3d n2 = c2 * m2 - m1; Eigen::Vector3d n3 = c3 * m4 - m1; //Compute rotation matrix columns Eigen::Vector3d R1 = _K.inverse() * n2; R1 = R1 / R1.norm(); Eigen::Vector3d R2 = _K.inverse() * n3; R2 = R2 / R2.norm(); Eigen::Vector3d R3 = R1.cross(R2); //Compute frame quaternion Eigen::Matrix3d R; R << R1, R2, R3; const Eigen::Quaterniond qOC(R); Eigen::Quaterniond Fqhat = Cq * qOC; //Compute frame transaltion Eigen::Matrix3d omega = _K.transpose().inverse() * _K.inverse(); double ff = sqrt( (n2.transpose() * omega * n2)[0] / (n3.transpose() * omega * n3)[0]); Eigen::Vector3d CtOhat = lambda * _K.inverse() * m1; Eigen::Vector3d Fthat = Ct + Cq.toRotationMatrix() * CtOhat; //compute shape parameters Eigen::Vector3d X = _K * R1; Eigen::Vector3d Y = c2 * lambda * m2 - lambda * m1; double w = ((X.transpose() * X).inverse() * X.transpose() * Y)[0]; double h = w / ff; //Write the results shapeParams << w, h; F << Fthat[0], Fthat[1], Fthat[2], Fqhat.w(), Fqhat.x(), Fqhat.y(), Fqhat.z(); }
void AnchoredRectangleHandler::initRectangle(const Eigen::VectorXd& Fw, double lambda, const Eigen::VectorXd& z, Eigen::VectorXd& shapeParamshat, Eigen::VectorXd& FOhphat, Eigen::VectorXd &FOqhat) { //Get the points Eigen::Vector3d m1(z[0], z[1], 1); Eigen::Vector3d m2(z[2], z[3], 1); Eigen::Vector3d m3(z[4], z[5], 1); Eigen::Vector3d m4(z[6], z[7], 1); Eigen::Vector3d Ft(Fw[0], Fw[1], Fw[2]); Eigen::Quaterniond Fq(Fw[3], Fw[4], Fw[5], Fw[6]); //compute normals double c2 = (m1.cross(m3).transpose() * m4)[0] / (m2.cross(m3).transpose() * m4)[0]; double c3 = (m1.cross(m3).transpose() * m2)[0] / (m4.cross(m3).transpose() * m2)[0]; Eigen::Vector3d n2 = c2 * m2 - m1; Eigen::Vector3d n3 = c3 * m4 - m1; //Compute rotation matrix columns Eigen::Vector3d R1 = _K.inverse() * n2; R1 = R1 / R1.norm(); Eigen::Vector3d R2 = _K.inverse() * n3; R2 = R2 / R2.norm(); Eigen::Vector3d R3 = R1.cross(R2); //Compute rotation from camera to object Eigen::Matrix3d R; R << R1, R2, R3; Eigen::Quaterniond FOq_e(R); // and initialize the of the object with respect to the anchor frame FOqhat << FOq_e.w(), FOq_e.x(), FOq_e.y(), FOq_e.z(); // now initialize lower left corner homogeneous point FOhphat << z[0], z[1], 1.0; FOhphat = _K.inverse() * FOhphat; FOhphat(2) = 1.0 / lambda; // 1/d distance of the plane parallel to the image plane on which features are initialized. //Compute frame transaltion Eigen::Matrix3d omega = _K.transpose().inverse() * _K.inverse(); double ff = sqrt( (n2.transpose() * omega * n2)[0] / (n3.transpose() * omega * n3)[0]); //compute shape parameters Eigen::Vector3d X = _K * R1; Eigen::Vector3d Y = c2 * lambda * m2 - lambda * m1; double w = ((X.transpose() * X).inverse() * X.transpose() * Y)[0]; //Write the results shapeParamshat << ff, w / lambda; }
int main() { struct funcs fs; fs.val = 42; fs.ps = pstr; f (f (23)); m1 (); m2 (); m4 (&fs, 0); m4 (&fs, 1); return 0; /* last break here */ }
void Camera::OnRender() { Matrix3 m3 = Matrix3::IDENTITY;; mOrientation.ToRotationMatrix(m3); Matrix4 m4(m3); glMultMatrixf(&m4[0][0]); glTranslatef(-mPosition.x, -mPosition.y, -mPosition.z); }
void RandomModel::materialsProduce() { Material m1(1.5, "glass"); // 玻璃 Material m2(2.5, "steel"); // 钢 Material m3(1.4, "aluminum"); // 铝 Material m4(1.6, "concrete"); // 水泥 this->materials.push_back(m1); this->materials.push_back(m2); this->materials.push_back(m3); this->materials.push_back(m4); }
// New test for Bug in SparseTimeDenseProduct template<typename SparseMatrixType, typename DenseMatrixType> void sparse_product_regression_test() { // This code does not compile with afflicted versions of the bug SparseMatrixType sm1(3,2); DenseMatrixType m2(2,2); sm1.setZero(); m2.setZero(); DenseMatrixType m3 = sm1*m2; // This code produces a segfault with afflicted versions of another SparseTimeDenseProduct // bug SparseMatrixType sm2(20000,2); sm2.setZero(); DenseMatrixType m4(sm2*m2); VERIFY_IS_APPROX( m4(0,0), 0.0 ); }
/* **************************************************************************** * * present - no output expected, just exercising the code */ TEST(Metadata, present) { Metadata m4("Name", "Type", "Value"); utInit(); m4.present("Test", 0, ""); m4.release(); utExit(); }
MatrixXd Utils::calculateHomographyMatrixFromFiveOrtoghonalLines(QList<Line*> firstOrtoghonalLines, QList<Line*> secondOrthogonalLines, QList<Line*> thirdOrthogonalLines, QList<Line*> fourthOrthogonalLines, QList<Line*> fifthOrthogonalLines) { // A * x = b. MatrixXd A(5, 6); MatrixXd b(5, 1); MatrixXd x(5, 1); Vector3d l1 = getLineInHomogeneousCoordinates(firstOrtoghonalLines.at(0)); Vector3d m1 = getLineInHomogeneousCoordinates(firstOrtoghonalLines.at(1)); Vector3d l2 = getLineInHomogeneousCoordinates(secondOrthogonalLines.at(0)); Vector3d m2 = getLineInHomogeneousCoordinates(secondOrthogonalLines.at(1)); Vector3d l3 = getLineInHomogeneousCoordinates(thirdOrthogonalLines.at(0)); Vector3d m3 = getLineInHomogeneousCoordinates(thirdOrthogonalLines.at(1)); Vector3d l4 = getLineInHomogeneousCoordinates(fourthOrthogonalLines.at(0)); Vector3d m4 = getLineInHomogeneousCoordinates(fourthOrthogonalLines.at(1)); Vector3d l5 = getLineInHomogeneousCoordinates(fifthOrthogonalLines.at(0)); Vector3d m5 = getLineInHomogeneousCoordinates(fifthOrthogonalLines.at(1)); b << -l1(1)*m1(1), -l2(1)*m2(1), -l3(1)*m3(1), -l4(1)*m4(1), -l5(1)*m5(1); A << l1(0)*m1(0), (l1(0)*m1(1)+l1(1)*m1(0))/2, l1(1)*m1(1), (l1(0)*m1(2)+l1(2)*m1(0))/2, (l1(1)*m1(2)+l1(2)*m1(1))/2, l1(2)*m1(2), l2(0)*m2(0), (l2(0)*m2(1)+l2(1)*m2(0))/2, l2(1)*m2(1), (l2(0)*m2(2)+l2(2)*m2(0))/2, (l2(1)*m2(2)+l2(2)*m2(1))/2, l2(2)*m2(2), l3(0)*m3(0), (l3(0)*m3(1)+l3(1)*m3(0))/2, l3(1)*m3(1), (l3(0)*m3(2)+l3(2)*m3(0))/2, (l3(1)*m3(2)+l3(2)*m3(1))/2, l3(2)*m3(2), l4(0)*m4(0), (l4(0)*m4(1)+l4(1)*m4(0))/2, l4(1)*m4(1), (l4(0)*m4(2)+l4(2)*m4(0))/2, (l4(1)*m4(2)+l4(2)*m4(1))/2, l4(2)*m4(2), l5(0)*m5(0), (l5(0)*m5(1)+l5(1)*m5(0))/2, l5(1)*m5(1), (l5(0)*m5(2)+l5(2)*m5(0))/2, (l5(1)*m5(2)+l5(2)*m5(1))/2, l5(2)*m5(2); x = A.colPivHouseholderQr().solve(b); x/=x(2); Matrix3d C; C << x(0), x(1)/2, x(3)/2, x(1)/2, x(2), x(4)/2, x(3)/2, x(4)/2, 1; Matrix2d kkt; kkt << C(0,0), C(0,1), C(1,0), C(1,1); MatrixXd vKKt(1,2); vKKt << C(2,0), C(2,1); MatrixXd V(1,2); V = vKKt * kkt.inverse(); LLT<MatrixXd> llt(kkt); MatrixXd U = llt.matrixU(); MatrixXd J (3,3); J << U(0,0), U(0,1),0, U(1,0), U(1,1),0, V(0), V(1), 1; return J; }
vector<Material> materialList() { // 玻璃 Material m1(1.5, "glass"); // 钢 Material m2(2.5, "steel"); // 铝 Material m3(1.4, "aluminum"); // 水泥 Material m4(1.6, "concrete"); vector<Material> materials; materials.push_back(m1); materials.push_back(m2); materials.push_back(m3); materials.push_back(m4); return materials; }
static void copy_ctor() { typedef const char* SrcKey; typedef std::string DstKey; typedef int SrcValue; typedef double DstValue; typedef Sawyer::Container::HashMap<SrcKey, SrcValue> SrcMap; typedef Sawyer::Container::HashMap<DstKey, DstValue> DstMap; SrcMap m1; m1.insert("aaa", 1); m1.insert("bbb", 2); ASSERT_always_require(m1.size()==2); const SrcMap m2(m1); ASSERT_always_require(m2.size()==m1.size()); DstMap m3(m1); ASSERT_always_require(m3.size()==m1.size()); DstMap m4(m2); ASSERT_always_require(m4.size()==m2.size()); }
bool CustomPoiMatch::isConflicting(const Match& other, const ConstOsmMapPtr& map) const { const CustomPoiMatch* cpm = dynamic_cast<const CustomPoiMatch*>(&other); if (cpm == 0) { return true; } else { shared_ptr<const MatchThreshold> mt(new MatchThreshold()); // if they don't have any EIDs in common then it isn't a conflict. if (_eid1 != cpm->_eid1 && _eid2 != cpm->_eid2 && _eid1 != cpm->_eid2 && _eid2 != cpm->_eid1) { return false; } // make sure all combinations of matches are also considered matches. CustomPoiMatch m1(map, _rf, _eid1, cpm->_eid1, mt); CustomPoiMatch m2(map, _rf, _eid1, cpm->_eid2, mt); CustomPoiMatch m3(map, _rf, _eid2, cpm->_eid1, mt); CustomPoiMatch m4(map, _rf, _eid2, cpm->_eid2, mt); if (m1.getType() == MatchType::Match && m2.getType() == MatchType::Match && m3.getType() == MatchType::Match && m4.getType() == MatchType::Match) { return false; } else { return true; } } }
int main() { // creates a 3x3 matrix Matrix a(3, 3); Matrix b(3, 3); Matrix c(3, 3); for(int i = 0; i < a.getRows(); i++) { for(int j = 0; j < a.getCols(); j++) { a[i][j] = 1; b[i][j] = 2; c[i][j] = i + j; } } Matrix m1(a + b); m1.print(); std::cout << "\n"; Matrix m2(a - b); m2.print(); std::cout << "\n"; Matrix m3(a * b); m3.print(); std::cout << "\n"; Matrix m4(c.transpose()); m4.print(); std::cout << "\n"; return 0; }
void testSkipListNode() { SkipListNode head_bottom; SkipListNode head_mid; SkipListNode head_roof; head_roof.down = &head_mid; head_mid.down = &head_bottom; head_bottom.up = &head_mid; head_mid.up = &head_roof; SkipListNode b1(1), b2(2), b3(3), b4(4); SkipListNode m1(1), m2(2), m4(4); SkipListNode r1(1), r4(4); r1.down = &m1; m1.down = &b1; b1.up = &m1; m1.up = &r1; r4.down = &m4; m4.down = &b4; b4.up = &m4; m4.up = &r4; m2.down = &b2; b2.up = &m2; head_bottom.next = &b1; b1.next = &b2; b2.next = &b3; b3.next = &b4; b4.prev = &b3; b3.prev = &b2; b2.prev = &b1; b1.prev = &head_bottom; head_mid.next = &m1; m1.next = &m2; m2.next = &m4; m4.prev = &m2; m2.prev = &m1; m1.prev = &head_mid; head_roof.next = &r1; r1.next = &r4; r4.prev = &r1; r1.prev = &head_roof; std::cout<<head_roof; std::cout<<head_mid; std::cout<<head_bottom; }
/* **************************************************************************** * * check - */ TEST(Metadata, check) { Metadata m1("", "Type", "Value"); Metadata m2("Name", "Type", ""); Metadata m3("Name", "Association", "XXX"); Metadata m4("Name", "Type", "Value"); std::string checked; utInit(); checked = m1.check(RegisterContext, XML, "", "", 0); EXPECT_STREQ("missing metadata name", checked.c_str()); checked = m2.check(RegisterContext, JSON, "", "", 0); EXPECT_STREQ("missing metadata value", checked.c_str()); checked = m3.check(RegisterContext, XML, "", "", 0); EXPECT_STREQ("", checked.c_str()); checked = m4.check(RegisterContext, XML, "", "", 0); EXPECT_STREQ("OK", checked.c_str()); utExit(); }
template<typename MatrixType> void inverse(const MatrixType& m) { typedef typename MatrixType::Index Index; /* this test covers the following files: Inverse.h */ Index rows = m.rows(); Index cols = m.cols(); typedef typename MatrixType::Scalar Scalar; typedef typename NumTraits<Scalar>::Real RealScalar; typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, 1> VectorType; MatrixType m1(rows, cols), m2(rows, cols), mzero = MatrixType::Zero(rows, cols), identity = MatrixType::Identity(rows, rows); createRandomPIMatrixOfRank(rows,rows,rows,m1); m2 = m1.inverse(); VERIFY_IS_APPROX(m1, m2.inverse() ); VERIFY_IS_APPROX((Scalar(2)*m2).inverse(), m2.inverse()*Scalar(0.5)); VERIFY_IS_APPROX(identity, m1.inverse() * m1 ); VERIFY_IS_APPROX(identity, m1 * m1.inverse() ); VERIFY_IS_APPROX(m1, m1.inverse().inverse() ); // since for the general case we implement separately row-major and col-major, test that VERIFY_IS_APPROX(MatrixType(m1.transpose().inverse()), MatrixType(m1.inverse().transpose())); #if !defined(EIGEN_TEST_PART_5) && !defined(EIGEN_TEST_PART_6) //computeInverseAndDetWithCheck tests //First: an invertible matrix bool invertible; RealScalar det; m2.setZero(); m1.computeInverseAndDetWithCheck(m2, det, invertible); VERIFY(invertible); VERIFY_IS_APPROX(identity, m1*m2); VERIFY_IS_APPROX(det, m1.determinant()); m2.setZero(); m1.computeInverseWithCheck(m2, invertible); VERIFY(invertible); VERIFY_IS_APPROX(identity, m1*m2); //Second: a rank one matrix (not invertible, except for 1x1 matrices) VectorType v3 = VectorType::Random(rows); MatrixType m3 = v3*v3.transpose(), m4(rows,cols); m3.computeInverseAndDetWithCheck(m4, det, invertible); VERIFY( rows==1 ? invertible : !invertible ); VERIFY_IS_MUCH_SMALLER_THAN(internal::abs(det-m3.determinant()), RealScalar(1)); m3.computeInverseWithCheck(m4, invertible); VERIFY( rows==1 ? invertible : !invertible ); #endif // check in-place inversion if(MatrixType::RowsAtCompileTime>=2 && MatrixType::RowsAtCompileTime<=4) { // in-place is forbidden VERIFY_RAISES_ASSERT(m1 = m1.inverse()); } else { m2 = m1.inverse(); m1 = m1.inverse(); VERIFY_IS_APPROX(m1,m2); } }
/* We expect src_extent to have a one pixel border around all four sides * of dst_extent. */ static void demosaic (GeglProperties *op, GeglBuffer *src, const GeglRectangle *src_rect, GeglBuffer *dst, const GeglRectangle *dst_rect) { gint x,y; gint offset, doffset; gfloat *src_buf; gfloat *dst_buf; src_buf = g_new0 (gfloat, src_rect->width * src_rect->height * 1); dst_buf = g_new0 (gfloat, dst_rect->width * dst_rect->height * 3); gegl_buffer_get (src, src_rect, 1.0, babl_format ("Y float"), src_buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); offset = ROW + COL; doffset = 0; for (y=dst_rect->y; y<dst_rect->height + dst_rect->y; y++) { for (x=dst_rect->x; x<dst_rect->width + dst_rect->x; x++) { gfloat red=0.0; gfloat green=0.0; gfloat blue=0.0; if ((y + op->pattern%2)%2==0) { if ((x+op->pattern/2)%2==1) { /* GRG * BGB * GRG */ blue =(src_buf[offset-COL]+src_buf[offset+COL])/2.0; green=src_buf[offset]; red =(src_buf[offset-ROW]+src_buf[offset+ROW])/2.0; } else { /* RGR * GBG * RGR */ blue =src_buf[offset]; green=m4(src_buf[offset-ROW], src_buf[offset-COL], src_buf[offset+COL], src_buf[offset+ROW]); red =m4(src_buf[offset-ROW-COL], src_buf[offset-ROW+COL], src_buf[offset+ROW-COL], src_buf[offset+ROW+COL]); } } else { if ((x+op->pattern/2)%2==1) { /* BGB * GRG * BGB */ blue =m4(src_buf[offset-ROW-COL], src_buf[offset-ROW+COL], src_buf[offset+ROW-COL], src_buf[offset+ROW+COL]); green=m4(src_buf[offset-ROW], src_buf[offset-COL], src_buf[offset+COL], src_buf[offset+ROW]); red =src_buf[offset]; } else { /* GBG * RGR * GBG */ blue =(src_buf[offset-ROW]+src_buf[offset+ROW])/2.0; green=src_buf[offset]; red =(src_buf[offset-COL]+src_buf[offset+COL])/2.0; } } dst_buf [doffset*3+0] = red; dst_buf [doffset*3+1] = green; dst_buf [doffset*3+2] = blue; offset++; doffset++; } offset+=2; } gegl_buffer_set (dst, dst_rect, 0, babl_format ("RGB float"), dst_buf, GEGL_AUTO_ROWSTRIDE); g_free (src_buf); g_free (dst_buf); }
void funclike(void) { #define stringify(x) #x expect_string("5", stringify(5)); expect_string("x", stringify(x)); expect_string("x y", stringify(x y)); expect_string("x y", stringify( x y )); expect_string("x + y", stringify( x + y )); expect_string("x + y", stringify(/**/x/**/+/**//**/ /**/y/**/)); expect_string("x+y", stringify( x+y )); expect_string("'a'", stringify('a')); expect_string("'\\''", stringify('\'')); expect_string("\"abc\"", stringify("abc")); expect_string("ZERO", stringify(ZERO)); #define m1(x) x expect(5, m1(5)); expect(7, m1((5 + 2))); expect(8, m1(plus(5, 3))); expect(10, m1() 10); expect(14, m1(2 + 2 +) 10); #define m2(x) x + x expect(10, m2(5)); #define m3(x, y) x * y expect(50, m3(5, 10)); expect(11, m3(2 + 2, 3 + 3)); #define m4(x, y) x + y + TWO expect(17, m4(5, 10)); #define m6(x, ...) x + __VA_ARGS__ expect(20, m6(2, 18)); expect(25, plus(m6(2, 18, 5))); #define plus(x, y) x * y + plus(x, y) expect(11, plus(2, 3)); #undef plus #define plus(x, y) minus(x, y) #define minus(x, y) plus(x, y) expect(31, plus(30, 1)); expect(29, minus(30, 1)); // This is not a function-like macro. #define m7 (0) + 1 expect(1, m7); #define m8(x, y) x ## y expect(2, m8(TW, O)); expect(0, m8(ZERO,)); #define m9(x, y, z) x y + z expect(8, m9(1,, 7)); #define m10(x) x ## x expect_string("a", "a" m10()); #define hash_hash # ## # #define mkstr(a) # a #define in_between(a) mkstr(a) #define join(c, d) in_between(c hash_hash d) expect_string("x ## y", join(x, y)); int m14 = 67; #define m14(x) x expect(67, m14); expect(67, m14(m14)); int a = 68; #define glue(x, y) x ## y glue(a+, +); expect(69, a); #define identity(x) stringify(x) expect_string("aa A B aa C", identity(m10(a) A B m10(a) C)); #define identity2(x) stringify(z ## x) expect_string("zA aa A B aa C", identity2(A m10(a) A B m10(a) C)); #define m15(x) x x expect_string("a a", identity(m15(a))); #define m16(x) (x,x) expect_string("(a,a)", identity(m16(a))); }
template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& ref) { const int rows = ref.rows(); const int cols = ref.cols(); typedef typename SparseMatrixType::Scalar Scalar; enum { Flags = SparseMatrixType::Flags }; double density = std::max(8./(rows*cols), 0.01); typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix; typedef Matrix<Scalar,Dynamic,1> DenseVector; Scalar eps = 1e-6; SparseMatrixType m(rows, cols); DenseMatrix refMat = DenseMatrix::Zero(rows, cols); DenseVector vec1 = DenseVector::Random(rows); Scalar s1 = ei_random<Scalar>(); std::vector<Vector2i> zeroCoords; std::vector<Vector2i> nonzeroCoords; initSparse<Scalar>(density, refMat, m, 0, &zeroCoords, &nonzeroCoords); if (zeroCoords.size()==0 || nonzeroCoords.size()==0) return; // test coeff and coeffRef for (int i=0; i<(int)zeroCoords.size(); ++i) { VERIFY_IS_MUCH_SMALLER_THAN( m.coeff(zeroCoords[i].x(),zeroCoords[i].y()), eps ); if(ei_is_same_type<SparseMatrixType,SparseMatrix<Scalar,Flags> >::ret) VERIFY_RAISES_ASSERT( m.coeffRef(zeroCoords[0].x(),zeroCoords[0].y()) = 5 ); } VERIFY_IS_APPROX(m, refMat); m.coeffRef(nonzeroCoords[0].x(), nonzeroCoords[0].y()) = Scalar(5); refMat.coeffRef(nonzeroCoords[0].x(), nonzeroCoords[0].y()) = Scalar(5); VERIFY_IS_APPROX(m, refMat); /* // test InnerIterators and Block expressions for (int t=0; t<10; ++t) { int j = ei_random<int>(0,cols-1); int i = ei_random<int>(0,rows-1); int w = ei_random<int>(1,cols-j-1); int h = ei_random<int>(1,rows-i-1); // VERIFY_IS_APPROX(m.block(i,j,h,w), refMat.block(i,j,h,w)); for(int c=0; c<w; c++) { VERIFY_IS_APPROX(m.block(i,j,h,w).col(c), refMat.block(i,j,h,w).col(c)); for(int r=0; r<h; r++) { // VERIFY_IS_APPROX(m.block(i,j,h,w).col(c).coeff(r), refMat.block(i,j,h,w).col(c).coeff(r)); } } // for(int r=0; r<h; r++) // { // VERIFY_IS_APPROX(m.block(i,j,h,w).row(r), refMat.block(i,j,h,w).row(r)); // for(int c=0; c<w; c++) // { // VERIFY_IS_APPROX(m.block(i,j,h,w).row(r).coeff(c), refMat.block(i,j,h,w).row(r).coeff(c)); // } // } } for(int c=0; c<cols; c++) { VERIFY_IS_APPROX(m.col(c) + m.col(c), (m + m).col(c)); VERIFY_IS_APPROX(m.col(c) + m.col(c), refMat.col(c) + refMat.col(c)); } for(int r=0; r<rows; r++) { VERIFY_IS_APPROX(m.row(r) + m.row(r), (m + m).row(r)); VERIFY_IS_APPROX(m.row(r) + m.row(r), refMat.row(r) + refMat.row(r)); } */ // test SparseSetters // coherent setter // TODO extend the MatrixSetter // { // m.setZero(); // VERIFY_IS_NOT_APPROX(m, refMat); // SparseSetter<SparseMatrixType, FullyCoherentAccessPattern> w(m); // for (int i=0; i<nonzeroCoords.size(); ++i) // { // w->coeffRef(nonzeroCoords[i].x(),nonzeroCoords[i].y()) = refMat.coeff(nonzeroCoords[i].x(),nonzeroCoords[i].y()); // } // } // VERIFY_IS_APPROX(m, refMat); // random setter // { // m.setZero(); // VERIFY_IS_NOT_APPROX(m, refMat); // SparseSetter<SparseMatrixType, RandomAccessPattern> w(m); // std::vector<Vector2i> remaining = nonzeroCoords; // while(!remaining.empty()) // { // int i = ei_random<int>(0,remaining.size()-1); // w->coeffRef(remaining[i].x(),remaining[i].y()) = refMat.coeff(remaining[i].x(),remaining[i].y()); // remaining[i] = remaining.back(); // remaining.pop_back(); // } // } // VERIFY_IS_APPROX(m, refMat); VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, StdMapTraits> >(m,refMat,nonzeroCoords) )); #ifdef EIGEN_UNORDERED_MAP_SUPPORT VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, StdUnorderedMapTraits> >(m,refMat,nonzeroCoords) )); #endif #ifdef _DENSE_HASH_MAP_H_ VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, GoogleDenseHashMapTraits> >(m,refMat,nonzeroCoords) )); #endif #ifdef _SPARSE_HASH_MAP_H_ VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, GoogleSparseHashMapTraits> >(m,refMat,nonzeroCoords) )); #endif // test fillrand { DenseMatrix m1(rows,cols); m1.setZero(); SparseMatrixType m2(rows,cols); m2.startFill(); for (int j=0; j<cols; ++j) { for (int k=0; k<rows/2; ++k) { int i = ei_random<int>(0,rows-1); if (m1.coeff(i,j)==Scalar(0)) m2.fillrand(i,j) = m1(i,j) = ei_random<Scalar>(); } } m2.endFill(); VERIFY_IS_APPROX(m2,m1); } // test RandomSetter /*{ SparseMatrixType m1(rows,cols), m2(rows,cols); DenseMatrix refM1 = DenseMatrix::Zero(rows, rows); initSparse<Scalar>(density, refM1, m1); { Eigen::RandomSetter<SparseMatrixType > setter(m2); for (int j=0; j<m1.outerSize(); ++j) for (typename SparseMatrixType::InnerIterator i(m1,j); i; ++i) setter(i.index(), j) = i.value(); } VERIFY_IS_APPROX(m1, m2); }*/ // std::cerr << m.transpose() << "\n\n" << refMat.transpose() << "\n\n"; // VERIFY_IS_APPROX(m, refMat); // test basic computations { DenseMatrix refM1 = DenseMatrix::Zero(rows, rows); DenseMatrix refM2 = DenseMatrix::Zero(rows, rows); DenseMatrix refM3 = DenseMatrix::Zero(rows, rows); DenseMatrix refM4 = DenseMatrix::Zero(rows, rows); SparseMatrixType m1(rows, rows); SparseMatrixType m2(rows, rows); SparseMatrixType m3(rows, rows); SparseMatrixType m4(rows, rows); initSparse<Scalar>(density, refM1, m1); initSparse<Scalar>(density, refM2, m2); initSparse<Scalar>(density, refM3, m3); initSparse<Scalar>(density, refM4, m4); VERIFY_IS_APPROX(m1+m2, refM1+refM2); VERIFY_IS_APPROX(m1+m2+m3, refM1+refM2+refM3); VERIFY_IS_APPROX(m3.cwise()*(m1+m2), refM3.cwise()*(refM1+refM2)); VERIFY_IS_APPROX(m1*s1-m2, refM1*s1-refM2); VERIFY_IS_APPROX(m1*=s1, refM1*=s1); VERIFY_IS_APPROX(m1/=s1, refM1/=s1); VERIFY_IS_APPROX(m1+=m2, refM1+=refM2); VERIFY_IS_APPROX(m1-=m2, refM1-=refM2); VERIFY_IS_APPROX(m1.col(0).eigen2_dot(refM2.row(0)), refM1.col(0).eigen2_dot(refM2.row(0))); refM4.setRandom(); // sparse cwise* dense VERIFY_IS_APPROX(m3.cwise()*refM4, refM3.cwise()*refM4); // VERIFY_IS_APPROX(m3.cwise()/refM4, refM3.cwise()/refM4); } // test innerVector() { DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows); SparseMatrixType m2(rows, rows); initSparse<Scalar>(density, refMat2, m2); int j0 = ei_random(0,rows-1); int j1 = ei_random(0,rows-1); VERIFY_IS_APPROX(m2.innerVector(j0), refMat2.col(j0)); VERIFY_IS_APPROX(m2.innerVector(j0)+m2.innerVector(j1), refMat2.col(j0)+refMat2.col(j1)); //m2.innerVector(j0) = 2*m2.innerVector(j1); //refMat2.col(j0) = 2*refMat2.col(j1); //VERIFY_IS_APPROX(m2, refMat2); } // test innerVectors() { DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows); SparseMatrixType m2(rows, rows); initSparse<Scalar>(density, refMat2, m2); int j0 = ei_random(0,rows-2); int j1 = ei_random(0,rows-2); int n0 = ei_random<int>(1,rows-std::max(j0,j1)); VERIFY_IS_APPROX(m2.innerVectors(j0,n0), refMat2.block(0,j0,rows,n0)); VERIFY_IS_APPROX(m2.innerVectors(j0,n0)+m2.innerVectors(j1,n0), refMat2.block(0,j0,rows,n0)+refMat2.block(0,j1,rows,n0)); //m2.innerVectors(j0,n0) = m2.innerVectors(j0,n0) + m2.innerVectors(j1,n0); //refMat2.block(0,j0,rows,n0) = refMat2.block(0,j0,rows,n0) + refMat2.block(0,j1,rows,n0); } // test transpose { DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows); SparseMatrixType m2(rows, rows); initSparse<Scalar>(density, refMat2, m2); VERIFY_IS_APPROX(m2.transpose().eval(), refMat2.transpose().eval()); VERIFY_IS_APPROX(m2.transpose(), refMat2.transpose()); } // test prune { SparseMatrixType m2(rows, rows); DenseMatrix refM2(rows, rows); refM2.setZero(); int countFalseNonZero = 0; int countTrueNonZero = 0; m2.startFill(); for (int j=0; j<m2.outerSize(); ++j) for (int i=0; i<m2.innerSize(); ++i) { float x = ei_random<float>(0,1); if (x<0.1) { // do nothing } else if (x<0.5) { countFalseNonZero++; m2.fill(i,j) = Scalar(0); } else { countTrueNonZero++; m2.fill(i,j) = refM2(i,j) = Scalar(1); } } m2.endFill(); VERIFY(countFalseNonZero+countTrueNonZero == m2.nonZeros()); VERIFY_IS_APPROX(m2, refM2); m2.prune(1); VERIFY(countTrueNonZero==m2.nonZeros()); VERIFY_IS_APPROX(m2, refM2); } }