我在仿真软件中工作,对数组进行的众多操作之一就是将向量缩放一个数字。
我有这样的代码:
//Just some initialization code, don't bother about this part
int n = 10000;
std::vector<double> input(n, 42.0);
std::vector<double> output(input.size());
double alpha = 69.0;
//the actual calculation:
for (size_t i = 0; i < n; ++i) {
output[i] = input[i] * alpha;
}
我有可用的 MKL 库,因此如果我的计算是“就地”完成的,则可以编写以下内容:
cblas_dscal(n, alpha, &input[0], 1);
但是,这会改变input
变量,这不是我想要的。
我尝试使用,mkl_domatcopy()
但此操作非常慢。