在Qt坠毁时使用Armadillo

时间:2017-11-02 07:42:48

标签: c++ qt armadillo

出于某种原因,我应该和犰狳做一些工作。但是当我使用Qt Creator调试我的代码时,代码崩溃了。我发现问题所在,但我不明白为什么坠毁事件发生了。有些代码可以使用,但有些则不能。这是我的代码。

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = paintertest
TEMPLATE = app


SOURCES += main.cpp\
    mainwindow.cpp \
test1.cpp

HEADERS  += mainwindow.h \
    test1.h

FORMS    += mainwindow.ui

INCLUDEPATH += D:/program/engineering/armadillo-8.200.2/include




win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -
llibblas
else:win32:CONFIG(debug, debug|release): LIBS += -
L$$PWD/libBLAS_LAPACKwin32/ -llibblas
else:unix: LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -llibblas

INCLUDEPATH += $$PWD/libBLAS_LAPACKwin32
DEPENDPATH += $$PWD/libBLAS_LAPACKwin32

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -
lliblapack
else:win32:CONFIG(debug, debug|release): LIBS += -
L$$PWD/libBLAS_LAPACKwin32/ -lliblapack
else:unix: LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -lliblapack

INCLUDEPATH += $$PWD/libBLAS_LAPACKwin32
DEPENDPATH += $$PWD/libBLAS_LAPACKwin32

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -
lliblapacke
else:win32:CONFIG(debug, debug|release): LIBS += -
L$$PWD/libBLAS_LAPACKwin32/ -lliblapacke
else:unix: LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -lliblapacke

INCLUDEPATH += $$PWD/libBLAS_LAPACKwin32
DEPENDPATH += $$PWD/libBLAS_LAPACKwin32

mainwindow.h:

 #include <armadillo>
    #include <iostream>
    using namespace arma;
    using namespace std;

mainwindow.cpp:

 cout << "Armadillo version: " << arma_version::as_string() << endl;

 mat A(2,3);  // directly specify the matrix size (elements are 
uninitialised)

 cout << "A.n_rows: " << A.n_rows << endl;  // .n_rows and .n_cols are read only
 cout << "A.n_cols: " << A.n_cols << endl;

 A(1,2) = 456.0;  // directly access an element (indexing starts at 0)
 A.print("A:");

 A = 5.0;         // scalars are treated as a 1x1 matrix
 A.print("A:");

 A.set_size(4,5); // change the size (data is not preserved)

 A.fill(5.0);     // set all elements to a particular value
 A.print("A:");

 // endr indicates "end of row"
 A << 0.165300 << 0.454037 << 0.995795 << 0.124098 << 0.047084 << endr
   << 0.688782 << 0.036549 << 0.552848 << 0.937664 << 0.866401 << endr
   << 0.348740 << 0.479388 << 0.506228 << 0.145673 << 0.491547 << endr
   << 0.148678 << 0.682258 << 0.571154 << 0.874724 << 0.444632 << endr
   << 0.245726 << 0.595218 << 0.409327 << 0.367827 << 0.385736 << endr;

 A.print("A:");
 det(A);
#if 0
 // determinant
 cout << "det(A): " << det(A) << endl;

 // inverse
 cout << "inv(A): " << endl << inv(A) << endl;

 // save matrix as a text file
 A.save("A.txt", raw_ascii);

 // load from file
 mat B;
 B.load("A.txt");

 // submatrices
 cout << "B( span(0,2), span(3,4) ):" << endl << B( span(0,2), span(3,4) ) << endl;

   //  cout << "B( 0,3, size(3,2) ):" << endl << B( 0,3, size(3,2) ) << endl;

 cout << "B.row(0): " << endl << B.row(0) << endl;

 cout << "B.col(1): " << endl << B.col(1) << endl;

 // transpose
 cout << "B.t(): " << endl << B.t() << endl;

 // maximum from each column (traverse along rows)
 cout << "max(B): " << endl << max(B) << endl;

 // maximum from each row (traverse along columns)
 cout << "max(B,1): " << endl << max(B,1) << endl;

 // maximum value in B
 cout << "max(max(B)) = " << max(max(B)) << endl;

 // sum of each column (traverse along rows)
 cout << "sum(B): " << endl << sum(B) << endl;

 // sum of each row (traverse along columns)
 cout << "sum(B,1) =" << endl << sum(B,1) << endl;

 // sum of all elements
 cout << "accu(B): " << accu(B) << endl;

 // trace = sum along diagonal
 cout << "trace(B): " << trace(B) << endl;

 // generate the identity matrix
 mat C = eye<mat>(4,4);

 // random matrix with values uniformly distributed in the [0,1] interval
 mat D = randu<mat>(4,4);
 D.print("D:");

 // row vectors are treated like a matrix with one row
 rowvec r;
 r << 0.59119 << 0.77321 << 0.60275 << 0.35887 << 0.51683;
 r.print("r:");

 // column vectors are treated like a matrix with one column
 vec q;
 q << 0.14333 << 0.59478 << 0.14481 << 0.58558 << 0.60809;
 q.print("q:");

 // convert matrix to vector; data in matrices is stored column-by-column
 vec v = vectorise(A);
 v.print("v:");

 // dot or inner product
 cout << "as_scalar(r*q): " << as_scalar(r*q) << endl;

 // outer product
 cout << "q*r: " << endl << q*r << endl;

 // multiply-and-accumulate operation (no temporary matrices are created)
 cout << "accu(A % B) = " << accu(A % B) << endl;

 // example of a compound operation
 B += 2.0 * A.t();
 B.print("B:");

 // imat specifies an integer matrix
 imat AA;
 imat BB;

 AA << 1 << 2 << 3 << endr << 4 << 5 << 6 << endr << 7 << 8 << 9;
 BB << 3 << 2 << 1 << endr << 6 << 5 << 4 << endr << 9 << 8 << 7;

 // comparison of matrices (element-wise); output of a relational operator is a umat
 umat ZZ = (AA >= BB);
 ZZ.print("ZZ:");

 // cubes ("3D matrices")
 cube Q( B.n_rows, B.n_cols, 2 );

 Q.slice(0) = B;
 Q.slice(1) = 2.0 * B;

 Q.print("Q:");

 // 2D field of matrices; 3D fields are also supported
 field<mat> F(4,3);

 for(uword col=0; col < F.n_cols; ++col)
 for(uword row=0; row < F.n_rows; ++row)
   {
   F(row,col) = randu<mat>(2,3);  // each element in field<mat> is a matrix
   }

 F.print("F:");
#endif

此代码是Armadillo网站提供的示例。当我评论

det(A)

代码运行良好。但是当我取消注释det(A)时,代码崩溃了,控制台中没有错误显示。下一个代码也有同样的问题。谁可以帮我解决这个问题?非常感谢!

1 个答案:

答案 0 :(得分:0)

我在Win64 / QtCreator系统上遇到了同样的问题。 我正在为犰狳写自己的魔术包装。 一切顺利,直到我试图计算行列式。 应用程序崩溃了。 我复制了blas_win64_MT.dll和lapack_win64_MT.dll之后 到应用程序的文件夹(在我的情况下,它是构建/发布/) 现在没有崩溃,至少计算失败。