array 類別

表示用來將資料移至加速器的資料容器。

語法

template <typename value_type, int _Rank>
friend class array;

參數

value_type
資料的元素類型。

_排名
陣列的排名。

成員

公用建構函式

名稱 描述
array 建構函式 初始化 array 類別的新執行個體。
~array 解構函式 array終結 物件。

公用方法

名稱 描述
copy_to 將陣列的內容複寫到另一個陣列。
data 傳回陣列原始資料的指標。
get_accelerator_view 會傳 回代表陣列配置位置的 accelerator_view 物件。 此屬性只能在 CPU 上存取。
get_associated_accelerator_view 取得呼叫暫存建構函式來具 array 現化物件時,做為參數傳遞的第二 個accelerator_view 物件。
get_cpu_access_type 回陣列的access_type 。 這個方法只能在 CPU 上存取。
get_extent 回陣列的範圍物件。
reinterpret_as 傳回一維陣列,其中包含 物件中的所有 array 專案。
section 傳回位於指定原點之 array 物件的子區段,並選擇性地傳回具有指定範圍的 子區段。
view_as 傳回從 array 物件建構的array_view 物件。

公用運算子

名稱 描述
operator std::vector<value_type> 使用 copy(*this, vector) 以隱含方式將陣列轉換成 std:: vector 物件。
operator() 傳回參數所指定的專案值。
operator[] 傳回位於指定索引處的專案。
operator= 將指定 array 之物件的內容複寫到這個物件中。

公用常數

名稱 描述
rank 常數 儲存陣列的排名。

公用資料成員

名稱 描述
accelerator_view 取得accelerator_view 物件,表示配置陣列的位置。 此屬性只能在 CPU 上存取。
associated_accelerator_view 取得呼叫暫存建構函式來具 array 現化物件時,做為參數傳遞的第二 個accelerator_view 物件。
cpu_access_type 取得access_type ,表示 CPU 如何存取陣列的儲存體。
extent 取得定義陣列圖形的範圍。

備註

此類型 array<T,N> 代表位於特定位置的密集且一般(非不鋸齒) N 維陣列,例如加速器或 CPU。 陣列中專案的資料類型是 T ,其必須是與目標加速器相容的類型。 雖然排名 、 N (陣列是以靜態方式決定,而且是型別的一部分,但陣列的範圍是由執行時間決定,並使用 類別 extent<N> 表示。

陣列可以有任意數目的維度,不過某些功能是針對 array 排名一、二和三的物件特製化。 如果您省略維度引數,預設值為 1。

陣列資料會在記憶體中連續配置。 最小顯著維度中不同元素在記憶體中相鄰。

陣列會以邏輯方式視為實值型別,因為當陣列複製到另一個陣列時,就會執行深層複製。 兩個數組永遠不會指向相同的資料。

array<T,N> 類型用於數個案例:

  • 作為可用於加速器計算的資料容器。

  • 作為資料容器,用來保存主機 CPU 上的記憶體(可用來複製至其他陣列或從其他陣列複製記憶體)。

  • 做為預備物件,做為主機到裝置複本中快速媒介。

繼承階層架構

array

需求

標頭︰ amp.h

命名空間: 並行

~陣 列

array終結 物件。

~array() restrict(cpu);

accelerator_view

取得accelerator_view 物件,表示配置陣列的位置。 此屬性只能在 CPU 上存取。

__declspec(property(get= get_accelerator_view)) Concurrency::accelerator_view accelerator_view;

陣列

初始化陣列類別 的新實例 。 沒有的預設建構函式 array<T,N> 。 所有建構函式只會在 CPU 上執行。 無法在 Direct3D 目標上執行它們。

explicit array(
    const Concurrency::extent<_Rank>& _Extent) restrict(cpu);

explicit array(
    int _E0) restrict(cpu);

explicit array(
    int _E0,
    int _E1) restrict(cpu);

explicit array(
    int _E0,
    int _E1,
    int _E2) restrict(cpu);

array(
    const Concurrency::extent<_Rank>& _Extent,
    Concurrency::accelerator_view _Av
    access_type _Cpu_access_type = access_type_auto) restrict(cpu);

array(
    int _E0,
    Concurrency::accelerator_view _Av
    access_type _Cpu_access_type = access_type_auto) restrict(cpu);

array(
    int _E0,
    int _E1,
    Concurrency::accelerator_view _Av
    access_type _Cpu_access_type = access_type_auto) restrict(cpu);

array(
    int _E0,
    int _E1,
    int _E2,
    Concurrency::accelerator_view _Av
    access_type _Cpu_access_type = access_type_auto) restrict(cpu);

array(
    const Concurrency::extent<_Rank>& _Extent,
    Concurrency::accelerator_view _Av,
    Concurrency::accelerator_view _Associated_Av) restrict(cpu);

array(
    int _E0,
    accelerator_view _Av,
    Concurrency::accelerator_view _Associated_Av) restrict(cpu);

array(
    int _E0,
    int _E1,
    Concurrency::accelerator_view _Av,
    Concurrency::accelerator_view _Associated_Av) restrict(cpu);

array(
    int _E0,
    int _E1,
    int _E2,
    Concurrency::accelerator_view _Av,
    Concurrency::accelerator_view _Associated_Av) restrict(cpu);

template <typename _InputIterator>
array(
    const Concurrency::extent<_Rank>& _Extent,
    _InputIterator _Src_first,
    _InputIterator _Src_last) restrict(cpu);

template <typename _InputIterator>
array(
    const Concurrency::extent<_Rank>& _Extent,
    _InputIterator _Src_first) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    _InputIterator _Src_first,
    _InputIterator _Src_last) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    _InputIterator _Src_first) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    int _E1,
    _InputIterator _Src_first,
    _InputIterator _Src_last) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    int _E1,
    _InputIterator _Src_first) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    int _E1,
    int _E2,
    _InputIterator _Src_first,
    _InputIterator _Src_last) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    int _E1,
    int _E2,
    _InputIterator _Src_first) restrict(cpu);

template <typename _InputIterator>
array(
    const Concurrency::extent<_Rank>& _Extent,
    _InputIterator _Src_first,
    _InputIterator _Src_last,
    Concurrency::accelerator_view _Av
    access_type _Cpu_access_type = access_type_auto) restrict(cpu);

template <typename _InputIterator>
array(
    const Concurrency::extent<_Rank>& _Extent,
    _InputIterator _Src_first,
    Concurrency::accelerator_view _Av
    access_type _Cpu_access_type = access_type_auto) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    _InputIterator _Src_first,
    _InputIterator _Src_last,
    Concurrency::accelerator_view _Av
    access_type _Cpu_access_type = access_type_auto) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    _InputIterator _Src_first,
    Concurrency::accelerator_view _Av
    access_type _Cpu_access_type = access_type_auto) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    int _E1,
    _InputIterator _Src_first,
    _InputIterator _Src_last,
    Concurrency::accelerator_view _Av
    access_type _Cpu_access_type = access_type_auto) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    int _E1,
    _InputIterator _Src_first,
    Concurrency::accelerator_view _Av
    access_type _Cpu_access_type = access_type_auto) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    int _E1,
    int _E2,
    _InputIterator _Src_first,
    _InputIterator _Src_last,
    Concurrency::accelerator_view _Av,
    access_type _Cpu_access_type = access_type_auto) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    int _E1,
    int _E2,
    _InputIterator _Src_first,
    Concurrency::accelerator_view _Av
    access_type _Cpu_access_type = access_type_auto) restrict(cpu);

template <typename _InputIterator>
array(
    const Concurrency::extent<_Rank>& _Extent,
    _InputIterator _Src_first,
    _InputIterator _Src_last,
    Concurrency::accelerator_view _Av,
    Concurrency::accelerator_view _Associated_Av) restrict(cpu);

template <typename _InputIterator>
array(
    const Concurrency::extent<_Rank>& _Extent,
    _InputIterator _Src_first,
    Concurrency::accelerator_view _Av,
    Concurrency::accelerator_view _Associated_Av) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    _InputIterator _Src_first,
    _InputIterator _Src_last,
    Concurrency::accelerator_view _Av,
    Concurrency::accelerator_view _Associated_Av) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0, _InputIterator _Src_first,
    Concurrency::accelerator_view _Av,
    Concurrency::accelerator_view _Associated_Av) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    int _E1, _InputIterator _Src_first, _InputIterator _Src_last,
    Concurrency::accelerator_view _Av,
    Concurrency::accelerator_view _Associated_Av) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    int _E1, _InputIterator _Src_first,
    Concurrency::accelerator_view _Av,
    Concurrency::accelerator_view _Associated_Av) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    int _E1,
    int _E2, _InputIterator _Src_first, _InputIterator _Src_last,
    Concurrency::accelerator_view _Av,
    Concurrency::accelerator_view _Associated_Av) restrict(cpu);

template <typename _InputIterator>
array(
    int _E0,
    int _E1,
    int _E2, _InputIterator _Src_first,
    Concurrency::accelerator_view _Av,
    Concurrency::accelerator_view _Associated_Av) restrict(cpu);

explicit array(
    const array_view<const value_type, _Rank>& _Src) restrict(cpu);

array(
    const array_view<const value_type, _Rank>& _Src,
    accelerator_view _Av
    access_type _Cpu_access_type = access_type_auto) restrict(cpu);

array(
    const array_view<const value_type, _Rank>& _Src,
    accelerator_view _Av,
    accelerator_view _Associated_Av) restrict(cpu);

array(const array& _Other) restrict(cpu);

array(array&& _Other) restrict(cpu);

參數

_Associated_Av
指定陣列慣用目標位置的accelerator_view。

_Av
指定 陣列位置的 accelerator_view 物件。

_Cpu_access_type
CPU 上陣列所需的 access_type 。 此參數的預設值 access_type_auto 是將 CPU access_type 判斷保留給執行時間。 您可以使用 方法查詢 get_cpu_access_type 陣列的實際 CPU access_type

_程度
陣列每個維度中的範圍。

_E0
本節範圍最重要的元件。

_E1
本節範圍中下一個最重要的元件。

_E2
本節範圍中最重要的元件。

_InputIterator
輸入迭代器的類型。

_Src
要複製的物件。

_Src_first
來源容器中的起始反覆運算器。

_Src_last
來源容器中的結束反覆運算器。

_其他
其他資料來源。

_排名
區段的排名。

value_type
複製之專案的資料類型。

associated_accelerator_view

取得呼叫暫存建構函式來具 array 現化物件時,做為參數傳遞的第二 個accelerator_view 物件。

__declspec(property(get= get_associated_accelerator_view)) Concurrency::accelerator_view associated_accelerator_view;

copy_to

將 的內容 array 複製到另一個 array

void copy_to(
    array<value_type, _Rank>& _Dest) const ;

void copy_to(
    array_view<value_type, _Rank>& _Dest) const ;

參數

_Dest
要複製到其中的 array_view 物件。

cpu_access_type

取得這個陣列允許的 CPU access_type。

__declspec(property(get= get_cpu_access_type)) access_type cpu_access_type;

資料

傳回 之原始資料的 array 指標。

value_type* data() restrict(amp, cpu);

const value_type* data() const restrict(amp, cpu);

傳回值

陣列原始資料的指標。

extent

取得定義 之圖形的範圍 array 物件。

__declspec(property(get= get_extent)) Concurrency::extent<_Rank> extent;

get_accelerator_view

會傳 回accelerator_view 物件,代表設定物件的位置 array 。 此屬性只能在 CPU 上存取。

Concurrency::accelerator_view get_accelerator_view() const;

傳回值

accelerator_view物件,表示設定物件的位置 array

get_associated_accelerator_view

取得呼叫暫存建構函式來具 array 現化物件時,做為參數傳遞的第二 個accelerator_view 物件。

Concurrency::accelerator_view get_associated_accelerator_view() const ;

傳回值

傳遞至暫存建構函式的第二 accelerator_view物件。

get_cpu_access_type

傳回此陣列允許的 CPU access_type。

access_type get_cpu_access_type() const restrict(cpu);

傳回值

get_extent

傳回 的範圍 物件 array

Concurrency::extent<_Rank> get_extent() const restrict(amp,cpu);

傳回值

extentarray 物件。

operator std::vector<value_type>

使用 copy(*this, vector) 以隱含方式將陣列轉換成 std::vector 物件。

operator std::vector<value_type>() const restrict(cpu);

參數

value_type
向量專案的資料類型。

傳回值

vector<T> 別的物件,其中包含陣列中包含的資料複本。

operator()

傳回參數所指定的專案值。

value_type& operator() (const index<_Rank>& _Index) restrict(amp,cpu);

const value_type& operator() (const index<_Rank>& _Index) cons  t restrict(amp,cpu);

value_type& operator() (int _I0, int _I1) restrict(amp,cpu);

const value_type& operator() (int _I0, int _I1) const restrict(amp,cpu)  ;

value_type& operator() (int _I0, int _I1, int _I2) restrict(amp,cpu);

const value_type& operator() (int _I0, int _I1, int _I2) const restrict(amp,cpu);

typename details::_Projection_result_type<value_type,_Rank>::_Result_type operator()(int _I) restrict(amp,cpu);

typename details::_Projection_result_type<value_type,_Rank>::_Const_result_type operator()(int _I) const restrict(amp,cpu);

參數

_指數
專案的位置。

_I0
本節來源最重要的元件。

_I1
本節來源的下一到最重要元件。

_I2
本節來源最不重要的元件。

_I
專案的位置。

傳回值

參數所指定的專案值。

operator[]

傳回位於指定索引處的專案。

value_type& operator[](const index<_Rank>& _Index) restrict(amp,cpu);

const value_type& operator[]
    (const index<_Rank>& _Index) const restrict(amp,cpu);

typename details::_Projection_result_type<value_type,_Rank>::_Result_type operator[](int _i) restrict(amp,cpu);

typename details::_Projection_result_type<value_type,_Rank>::_Const_result_type operator[](int _i) const restrict(amp,cpu);

參數

_指數
索引。

_I
索引。

傳回值

位於指定索引處的專案。

operator=

複製指定 array 之 物件的內容。

array& operator= (const array& _Other) restrict(cpu);

array& operator= (array&& _Other) restrict(cpu);

array& operator= (
    const array_view<const value_type, _Rank>& _Src) restrict(cpu);

參數

_其他
array 從中複製的物件。

_Src
array 從中複製的物件。

傳回值

這個 array 物件的參考。

rank

儲存 的 array 排名。

static const int rank = _Rank;

reinterpret_as

透過一維array_view重新解譯陣列,其中選擇性地可能有與來源陣列不同的實數值型別。

語法

template <typename _Value_type2>
array_view<_Value_type2,1> reinterpret_as() restrict(amp,cpu);

template <typename _Value_type2>
array_view<const _Value_type2, 1> reinterpret_as() const restrict(amp,cpu);

參數

_Value_type2
傳回之資料的資料類型。

傳回值

以陣列為基礎的array_view或 const array_view 物件,元素類型會從 T 重新解譯為 ElementType,並將排名從 N 縮減為 1。

備註

有時候,檢視多維度陣列會很方便,就好像它是線性的一維陣列,可能具有與來源陣列不同的實數值型別。 您可以使用這個方法來達成此目的。 注意 使用不同實數值型別重新解譯陣列物件是可能不安全的作業。 建議您謹慎使用這項功能。

下列程式碼提供一個範例。

struct RGB { float r; float g; float b; };

array<RGB,3>  a = ...;
array_view<float,1> v = a.reinterpret_as<float>();

assert(v.extent == 3*a.extent);

section

傳回位於指定原點之 array 物件的子區段,並選擇性地傳回具有指定範圍的 子區段。

array_view<value_type,_Rank> section(
    const Concurrency::index<_Rank>& _Section_origin,
    const Concurrency::extent<_Rank>& _Section_extent) restrict(amp,cpu);

array_view<const value_type,_Rank> section(
    const Concurrency::index<_Rank>& _Section_origin,
    const Concurrency::extent<_Rank>& _Section_extent) const restrict(amp,cpu);

array_view<value_type,_Rank> section(
    const Concurrency::extent<_Rank>& _Ext) restrict(amp,cpu);

array_view<const value_type,_Rank> section(
    const Concurrency::extent<_Rank>& _Ext) const restrict(amp,cpu);

array_view<value_type,_Rank> section(
    const index<_Rank>& _Idx) restrict(amp,cpu);

array_view<const value_type,_Rank> section(
    const index<_Rank>& _Idx) const restrict(amp,cpu);

array_view<value_type,1> section(
    int _I0,
    int _E0) restrict(amp,cpu);

array_view<const value_type,1> section(
    int _I0,
    int _E0) const restrict(amp,cpu);

array_view<value_type,2> section(
    int _I0,
    int _I1,
    int _E0,
    int _E1) restrict(amp,cpu);

array_view<const value_type,2> section(
    int _I0,
    int _I1,
    int _E0,
    int _E1) const restrict(amp,cpu);

array_view<value_type,3> section(
    int _I0,
    int _I1,
    int _I2,
    int _E0,
    int _E1,
    int _E2) restrict(amp,cpu);

array_view<const value_type,3> section(
    int _I0,
    int _I1,
    int _I2,
    int _E0,
    int _E1,
    int _E2) const restrict(amp,cpu);

參數

_E0
本節範圍最重要的元件。

_E1
本節範圍中下一個最重要的元件。

_E2
本節範圍中最重要的元件。

_內線
指定區 段範圍的範圍物件。 原點為 0。

_Idx
指定原點位置的索引 物件。 子區段是範圍的其餘部分。

_I0
本節來源最重要的元件。

_I1
本節來源的下一到最重要元件。

_I2
本節來源最不重要的元件。

_排名
區段的排名。

_Section_extent
指定區 段範圍的範圍物件。

_Section_origin
指定原點位置的索引 物件。

value_type
複製之專案的資料類型。

傳回值

傳回位於指定原點之 array 物件的子區段,並選擇性地傳回具有指定範圍的 子區段。 當只 index 指定 物件時,子區段會包含相關聯方格中的所有專案,這些元素的索引大於 物件中 index 專案的索引。

view_as

將這個陣列重新解譯為 不同順位的array_view

template <int _New_rank>
array_view<value_type,_New_rank> view_as(
    const Concurrency::extent<_New_rank>& _View_extent) restrict(amp,cpu);

template <int _New_rank>
array_view<const value_type,_New_rank> view_as(
    const Concurrency::extent<_New_rank>& _View_extent) const restrict(amp,cpu);

參數

_New_rank
傳遞為參數的物件 extent 排名。

_View_extent
用來建構新 array_view 物件的範圍。

value_type
原始 array 物件和傳 array_view 回之 物件中的專案資料類型。

傳回值

建構array_view 物件。

另請參閱

Concurrency 命名空間 (C++ AMP)