gpt4 book ai didi

c++ - Windows 上的 Armadillo 和 Codeblocks

转载 作者:行者123 更新时间:2023-11-28 02:28:34 26 4
gpt4 key购买 nike

我在让 Armadillo 5.000.1 在 Windows 8.1 上使用 CodeBlocks 13.12 时遇到了很大的问题。


  • project build options -> linker settings 我添加了库 ..\armadillo-5.000.1\examples\lib_win64\blas_win64_MT.lib..\armadillo-5.000.1\examples\lib_win64\lapack_win64_MT.lib.
  • project build options->search directories 中,我添加了 ..\armadillo-5.000.1\include..\..\。 .\..\..\Program Files\mingw-w64\x86_64-4.9.2-posix-seh-rt_v4-rev2\mingw64\include 到编译器和 ..\armadillo-5.000.1\examples\lib_win64 到链接器。
  • 我在 config.hpp 中取消了对 #define ARMA_USE_LAPACK#define ARMA_USE_BLAS 的注释。
  • 我(我认为)正在使用 64 位 mingw 编译器。

当我运行 example1.cpp 文件时,出现以下错误:

-------------- Build: Debug in CS156b (compiler: GNU GCC Compiler)---------------

g++.exe -L..\armadillo-5.000.1\examples\lib_win64 -o bin\Debug\CS156b.exe obj\Debug\armadillo-5.000.1\examples\example1.o obj\Debug\load_data3.o ..\armadillo-5.000.1\examples\lib_win64\lapack_win64_MT.lib ..\armadillo-5.000.1\examples\lib_win64\blas_win64_MT.lib
..\armadillo-5.000.1\examples\lib_win64\lapack_win64_MT.lib: error adding symbols: File format not recognized
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

此外,我的队友编写的代码在她的 (Linux) 计算机上运行良好

#include <iostream>
#include <fstream>
#include <ctime>
#define ARMA_64BIT_WORD
#include <armadillo>

/*
* Read in data from the um.zip file all.dta
* and store in a sparse vector. There are
* 458293 reviewers and 17770 reviews.
*/

int main()
{
using namespace std;
clock_t begin = clock();

vector<double> ratings;
arma::umat locations = arma::umat(2, 102416306);

// Open the file
string line;
ifstream myfile("um/all.dta");
int c = 0;
if (myfile.is_open())
{
while (getline(myfile, line))
{
//cout << line << endl;
if (c % 100 == 0)
cout << c<< endl;


int space1 = line.find(" ");
int space2 = line.find(" ", space1 + 1);
int space3 = line.find(" ", space2 + 1);

// Insert into our temporary data vectors
locations(0, c) = atoi(line.substr(0, space1).c_str());
locations(1, c) = atoi(line.substr(space1 + 1, space2).c_str());
ratings.push_back(atoi(line.substr(space3 + 1).c_str()));
// cout << user << " " << review << " " << rating << endl;
/*
boost::split(split_line, line, boost::is_any_of(" "));

// Convert data to ints
for (unsigned int i = 0; i < split_line.size(); ++i)
{
line_data.push_back(atoi(split_line[i].c_str()));
}
*/

c += 1;


}
}

// Create the sparse matrix
arma::sp_mat m = arma::sp_mat(locations, arma::vec(ratings));

// Serialize the sparse matrix object
//fstream ofs("sparse_matrix_eigen");
//boost::archive::text_oarchive ar(ofs);

// Write data
//ar & m;

clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
cout << elapsed_secs << endl;

cout << m;

}

给我错误:

error: SpMat::SpMat(): number of locations is different than number of values

terminate called after throwing an instance of 'std::logic_error'
what(): SpMat::SpMat(): number of locations is different than number of values

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Process returned 255 (0xFF) execution time : 5.181 s
Press any key to continue.

有人知道我做错了什么吗?

最佳答案

问题 1:不幸的是,我不知道 Codeblocks 是什么。但是显然链接器不理解lapack_win64_MT.lib文件格式。这与 Armadillo 无关。你运行的是 64 位环境吗?您的链接器是否能够读取那些可能采用 Visual Studio 格式的库?我看到您在这里使用 g++,这可能是问题所在。

问题 2:您询问固定大小的位置矩阵,然后遍历文件的长度。问题可能是文件中的数据行太少,因此无法正确填充 sp_mat。

locations = arma::umat(2, 102416306);

应该相当动态地调整大小(来 self 的大脑的例子,不是 100& 保证工作):

int no_of_lines;
for (no_of_lines = 0; std::getline(f, line); ++no_of_lines);
locations = arma::umat(2, no_of_lines);

关于c++ - Windows 上的 Armadillo 和 Codeblocks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29687977/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com