久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從 C 數組初始化 ublas 向量

Initializing a ublas vector from a C array(從 C 數組初始化 ublas 向量)
本文介紹了從 C 數組初始化 ublas 向量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 C++ ublas 庫編寫一個 Matlab 擴展,我希望能夠從 Matlab interpeter 傳遞的 C 數組初始化我的 ublas 向量.如何在不(為了效率)顯式復制數據的情況下從 C 數組初始化 ublas 向量.我正在尋找以下代碼行的內容:

I am writing a Matlab extension using the C++ ublas library, and I would like to be able to initialize my ublas vectors from the C arrays passed by the Matlab interpeter. How can I initialize the ublas vector from a C array without (for the sake of efficiency) explicitly copying the data. I am looking for something along the following lines of code:

using namespace boost::numeric::ublas;

int pv[10] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };
vector<int> v (pv);

一般來說,是否可以從數組初始化 C++ std::vector ?像這樣:

In general, is it possible to initialize a C++ std::vector from an array? Something like this:

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int pv[4] = { 4, 4, 4, 4};
    vector<int> v (pv, pv+4);

    pv[0] = 0;
    cout << "v[0]=" << v[0] << " " << "pv[0]=" << pv[0] << endl;

    return 0;
}

但是在初始化時不會復制數據.在這種情況下,輸出是

but where the initialization would not copy the data. In this case the output is

v[0]=4 pv[0]=0

但我希望輸出相同,其中更新 C 數組會更改 C++ 向量指向的數據

but I want the output to be the same, where updating the C array changes the data pointed to by the C++ vector

v[0]=0 pv[0]=0

推薦答案

std::vectorublas::vector 都是容器.容器的全部意義在于管理其包含對象的存儲和生命周期.這就是為什么當您初始化它們時,它們必須將值復制到它們擁有的存儲中.

Both std::vector and ublas::vector are containers. The whole point of containers is to manage the storage and lifetimes of their contained objects. This is why when you initialize them they must copy values into storage that they own.

C 數組是大小和位置固定的內存區域,因此就其性質而言,您只能通過復制將它們的值放入容器中.

C arrays are areas of memory fixed in size and location so by their nature you can only get their values into a container by copying.

您可以使用 C 數組作為許多算法函數的輸入,所以也許您可以這樣做以避免初始副本?

You can use C arrays as the input to many algorithm functions so perhaps you can do that to avoid the initial copy?

這篇關于從 C 數組初始化 ublas 向量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 狠狠色综合网站久久久久久久 | 午夜丰满少妇一级毛片 | 狠狠爱一区二区三区 | 国产精品久久久久久久久久久久久久 | 五月激情婷婷在线 | 国产精品国产三级国产a | 天天久久 | 国产黄色在线观看 | 久久久久久久久久久久久久久久久久久久 | 欧美日韩一区在线观看 | 国产精品99999 | 欧美黄色片 | 久草综合在线视频 | 欧美激情国产日韩精品一区18 | 狠狠躁夜夜躁人人爽天天高潮 | 日韩中文一区 | 日本超碰| 91色网站 | 福利网址| 精品久久久久久久久久久久久 | 日本免费一区二区三区视频 | 日本一二三区在线观看 | 在线国产一区 | 亚洲精品区| 亚洲天堂av在线 | 亚洲成av人片在线观看无码 | 免费一级黄色电影 | 伊人导航| 在线观看国产视频 | 亚洲欧美日韩中文字幕一区二区三区 | 亚洲精品久久久久久久久久久久久 | 国产九九九 | 涩涩视频网站在线观看 | 久久一二区 | 国产精品久久久久久婷婷天堂 | 亚洲免费在线视频 | 久久精品美女 | 成人在线欧美 | 亚洲色欲色欲www | 97精品超碰一区二区三区 | 国产女人与拘做受视频 |