Eigen 是否制作任何中间数组来计算 x 或 Eigen 只是将值放入 simd 寄存器并进行计算?
一般来说,如何知道 Eigen 制作了多少个中间体?
Eigen 会在循环的每个循环中为中间体分配新的内存吗?
无论如何确保本征不会产生任何中间体?它有像“EIGEN_NO_INTERMEDIATE”这样的宏吗?
#include <Eigen/Eigen>
#include <iostream>
using namespace Eigen;
template<typename T>
void fill(T& x) {
for (int i = 0; i < x.size(); ++i) x.data()[i] = i + 1;
}
int main() {
int n = 10; // n is actually about 400
ArrayXXf x(n, n);
ArrayXf y(n);
fill(x);
fill(y);
for (int i = 0; i < 10; ++i) { // many cycles
x = x * ((x.colwise() …Run Code Online (Sandbox Code Playgroud) 在多次简化我的代码后,我发现了以下问题的原因。
class B {
public:
B(const int x)
:_x(x) {}
const int _x;
};
class C {
public:
C(const B& b)
: _b(b), _b2(_b._x) {}
B _b2; // line 1
const B& _b; // line 2
};
int main() {
B b(1);
C c(b);
}
Run Code Online (Sandbox Code Playgroud)
警告 (clang 8.0.0)
test16.cpp:11:22: warning: reference '_b' is not yet bound to a value when used here [-Wuninitialized]
: _b(b), _b2(_b._x) {}
^
1 warning generated.
Run Code Online (Sandbox Code Playgroud)
g++-6 编译程序。运行该程序会导致分段错误。
类成员的初始化是遵循成员初始化列表: _b(b), _b2(_b._x)的顺序()还是类中成员的顺序(如B _b2; …
如何隐藏库中的导入内容?
库.py
import numpy as np
Run Code Online (Sandbox Code Playgroud)
测试.py
import library
print(dir(library))
Run Code Online (Sandbox Code Playgroud)
结果(python3 test.py)
['__builtins__', '__cached__', '__doc__', '__file__',
'__loader__', '__name__', '__package__', '__spec__',
'np']
Run Code Online (Sandbox Code Playgroud)
问题:np是库的一个模块。
隐藏我用来编写库的库的明智方法是什么?
我尝试将另一个模板参数添加到元编程的阶乘示例中.但以下不起作用.什么是正确的方法?
码:
#include <iostream>
template <typename T, int Depth>
inline void loop(T i){
std::cout << i;
loop<T, Depth-1>(i - 1);
}
template <typename T, int Depth>
inline void loop<T, 0>(T i){
std::cout << i << std::endl;
}
int main(void){
int i = 10;
loop<int, 3>(i);
}
Run Code Online (Sandbox Code Playgroud)
错误:
test4.cpp(9): error: an explicit template argument list is not allowed on this declaration
inline void loop<T, 0>(T i){
Run Code Online (Sandbox Code Playgroud)