久久久久久久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 ()?環形?)
主站蜘蛛池模板: 日韩欧美在线一区 | 国产97人人超碰caoprom | 亚洲不卡一 | 精品国产一区二区国模嫣然 | a欧美| 国产农村妇女精品一区 | 在线黄av| 伊人国产精品 | 成人免费视频网站在线看 | 成人毛片视频免费 | 日韩精品不卡 | 亚洲视频自拍 | 亚洲精品乱码久久久久v最新版 | 成人超碰 | 欧美日韩一 | 亚洲一区免费在线 | 亚洲人成免费 | 日韩国产精品一区二区三区 | 国产一区二区三区在线视频 | 精品免费国产一区二区三区 | 欧美三级电影在线播放 | 最新免费av网站 | 日韩在线成人 | 免费一级黄色电影 | 亚洲资源在线 | 玖玖在线免费视频 | 欧美亚洲另类在线 | 色精品视频 | 狠狠色综合网站久久久久久久 | 亚洲嫩草 | 亚洲高清网| 特黄毛片 | 成人精品免费视频 | 亚洲欧洲小视频 | 日韩中文字幕视频 | 精品不卡| 欧美日韩一 | 午夜影院在线观看 | 日韩福利视频 | 国产极品粉嫩美女呻吟在线看人 | 91九色网站 |