ublas:将ublas :: vector包装为ublas :: matrix_expression [英] ublas: Wrap ublas::vector as ublas::matrix_expression

查看:96
本文介绍了ublas:将ublas :: vector包装为ublas :: matrix_expression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Boost :: uBLAS上是个菜鸟.

I'm a very noob at Boost::uBLAS.

我有一个将ublas::matrix_expression<double>作为输入的函数:

I have a function which take a ublas::matrix_expression<double> as input:

namespace ublas = boost::numeric::ublas;

void Func(const ublas::matrix_expression<double>& in,
                ublas::matrix_expression<double>& out);

一个调用者将行向量保存为ublas::vector<double>,我希望将其传递给Func.

A caller is holding a row vector as ublas::vector<double>, and I want it to be passed to Func.

直到现在,我还没有找到实现此目的的任何方法.
最好的方法是什么,最好是没有任何临时分配?

Until now I have not found any way to do this.
What is the best way, preferably without any temporary allocation?

谢谢.

推荐答案

嗯,有一个选项可以将连续内存区域的只读适配器创建为只读矩阵.看看示例3 .使用起来非常简单:

Well, there is an option to create a read-only adapter of a contiguous area of memory into a read-only matrix. Have a look at example 3. It is pretty straightforward to use:

#include "storage_adaptors.hpp"
#include <boost/numeric/ublas/assignment.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>

ublas::vector<double> v(6);
v <<= 1, 2, 3, 4, 5, 6;
ublas::matrix<double> m = ublas::make_matrix_from_pointer(2, 3, &v(0));
std::cout << m << std::endl;

可能您可以进一步调整以适合您的需求/示例.

Possibly you could tweak that further to fit your needs/example.

这篇关于ublas:将ublas :: vector包装为ublas :: matrix_expression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆