C++ 设置大特征向量xd时出现叮当声错误

C++ 设置大特征向量xd时出现叮当声错误,c++,clang,eigen,C++,Clang,Eigen,我有一个函数,它所做的就是 Eigen::VectorXd x(%s); x << %s; Eigen::VectorXd x(%s); x 4000个参数)一切都很好。但是,当我在较大的计算机上运行它时,我无法编译,并且 clang: error: unable to execute command: Illegal instruction: 4 clang: error: clang frontend command failed due to signal (use -v t

我有一个函数,它所做的就是

Eigen::VectorXd x(%s);
x << %s;
Eigen::VectorXd x(%s);
x 4000个参数)一切都很好。但是,当我在较大的计算机上运行它时,我无法编译,并且

clang: error: unable to execute command: Illegal instruction: 4
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
clang: note: diagnostic msg: PLEASE submit a bug report to http://developer.apple.com/bugreporter/ and include the crash backtrace, preprocessed source, and associated run script.
clang: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /var/folders/jc/nh9bfd2j5_q4w0x2mbq02svc0000gq/T/wenzel-f181fc.cpp
clang: note: diagnostic msg: /var/folders/jc/nh9bfd2j5_q4w0x2mbq02svc0000gq/T/wenzel-f181fc.sh
clang: note: diagnostic msg: Crash backtrace is located in
clang: note: diagnostic msg: /Users/ipq500/Library/Logs/DiagnosticReports/clang_<YYYY-MM-DD-HHMMSS>_<hostname>.crash
clang: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
clang: note: diagnostic msg:

********************
clang:错误:无法执行命令:非法指令:4
clang:错误:由于信号原因,clang前端命令失败(使用-v查看调用)
苹果LLVM版本10.0.1(clang-1001.0.46.4)
目标:x86_64-apple-darwin18.6.0
线程模型:posix
InstalledDir:/Library/Developer/CommandLineTools/usr/bin
叮当声:注意:诊断信息:请向http://developer.apple.com/bugreporter/ 并包括崩溃回溯、预处理的源代码和相关的运行脚本。
叮当声:注意:诊断信息:
********************
请将以下文件附加到错误报告:
预处理源和关联的运行脚本位于:
提示:诊断消息:/var/folders/jc/nh9bfd2j5_q4w0x2mbq02svc0000gq/T/wenzel-f181fc.cpp
提示:诊断信息:/var/folders/jc/nh9bfd2j5_q4w0x2mbq02svc0000gq/T/wenzel-f181fc.sh
叮当声:注意:诊断信息:崩溃回溯位于
叮当声:注意:诊断消息:/Users/ipq500/Library/Logs/DiagnosticReports/clang\uuuuu.crash
叮当声:注意:诊断消息:(选择与崩溃对应的.crash文件)
叮当声:注意:诊断信息:
********************

我知道这可能是一个XCode问题,但我想知道可能发生了什么。我在这里完全不知所措。

我想你想做的是

Eigen::VectorXd x(4000);
x << 0, 1, 2, 3, /* many more values */ 3999;
这对于编译器来说确实很难翻译,因为您有一个4000深度的调用堆栈(尽管这将内联,但在编译时可能会触发一些限制)

使用C++11和开发分支,您可以尝试以下方法(不确定该语法的编译器限制):

如果不起作用,请尝试此替代方案(C++03兼容):

static const x_data[4000]={0,1,2,/*…*/,3999};//理想情况下,这应该是一致的
特征:映射x(x_数据,4000);

或者,如果数据是二进制形式的(例如,在一个单独的文件中),则运行时
mmap
该文件并在该数据上创建一个
Eigen::Map

是否
%s
真的是一个变量的名称?您应该提供一个实际值。问题可能在其他任何一点上。
operator,( /* many more calls ... */
  operator,(operator,(operator,(operator<<(x,0), 1), 2), 3)
           /* ... */, 3999 );
Eigen::VectorXd x{ {0, 1, 2, 3, /* ... */ 3999} };
static const x_data[4000] = {0,1,2, /* ... */, 3999}; // ideally this should be aligned
Eigen::Map<Eigen::VectorXd> x(x_data, 4000);