表示用來將數據移至加速器的數據容器。
語法
template <typename value_type, int _Rank>
friend class array;
參數
value_type
數據的元素類型。
_排行
陣列的排名。
成員
公開建構函式
| 名稱 | 描述 |
|---|---|
| array 建構函式 | 初始化 array 類別的新執行個體。 |
| ~array 解構函式 | 銷毀array物件。 |
公用方法
| 名稱 | 描述 |
|---|---|
| copy_to | 將陣列的內容複製到另一個陣列。 |
| 數據 | 傳回指向陣列原始數據的指標。 |
| 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 物件中所有元素的一維陣列。 |
| 章節 | 傳回位於指定原點之 array 物件的子區段,並選擇性地傳回具有指定範圍的 子區段。 |
| view_as | 返回一個由array物件構建的array_view物件。 |
公用運算子
| 名稱 | 描述 |
|---|---|
operator std::vector<value_type> |
使用 copy(*this, vector) 以隱含方式將陣列轉換成 std::vector 物件。 |
| operator() | 傳回參數所指定的項目值。 |
| operator[] | 返回位於指定索引處的元素。 |
| 運算子= | 將指定 array 之物件的內容複製到這個物件中。 |
公用常數
| 名稱 | 描述 |
|---|---|
| rank 常數 | 儲存陣列的排名。 |
公用資料成員
| 名稱 | 描述 |
|---|---|
| accelerator_view | 取得accelerator_view物件,代表陣列配置的位置。 此屬性只能在 CPU 上存取。 |
| associated_accelerator_view | 取得呼叫過渡建構函式來實例化array物件時,做為參數傳遞的第二個accelerator_view物件。 |
| cpu_access_type | 取得access_type,表示CPU如何存取陣列的儲存空間。 |
| 範圍 | 取得定義陣列形狀的範圍。 |
備註
此類型 array<T,N> 代表位於特定位置的密集且一般(非不鋸齒) N 維陣列,例如加速器或 CPU。 陣列中項目的數據類型是 T,其必須是與目標加速器相容的類型。 雖然陣列的秩N是以靜態方式決定,而且是型別的一部分,而陣列的範圍是由執行期決定,並使用類別extent<N>表示。
陣列可以有任意數目的維度,不過某些功能是專門設計給維度為一、二和三的 array 物件。 如果您省略維度自變數,預設值為1。
陣列資料在記憶體中緊密地配置。 最低有效維度中差異為一的元素在記憶體中相鄰。
陣列會以邏輯方式視為實值型別,因為當陣列複製到另一個陣列時,就會執行深層複製。 兩個陣列永遠不會指向相同的數據。
此 array<T,N> 類型用於數個案例:
作為可用於加速器計算的數據容器。
作為數據容器,用來保存主機 CPU 所使用的記憶體(可用來複製至其他陣列或從其他陣列複製)。
作為一個預備物件,用於主機到設備間的快速中介資料傳輸。
繼承階層架構
array
需求
標頭︰ amp.h
命名空間: 並行
~陣列
銷毀array物件。
~array() restrict(cpu);
加速器視圖
取得代表陣列配置位置的 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方法查詢陣列的實際 CPUaccess_type。
_程度
陣列每個維度中的範圍。
_E0
本節範圍中最具重要性的成分。
_E1
本節範圍中下一個最重要的元件。
_E2
本節範圍中最不重要的元件。
_InputIterator
輸入迭代器的類型。
_Src
反對複製。
_Src_first
來源容器中的起始迭代器。
_Src_last
來源容器中的結束迭代器。
_其他
其他數據源。
_排行
區段的排名。
value_type
複製之項目的數據類型。
關聯加速器視圖
取得呼叫過渡建構函式來實例化array物件時,做為參數傳遞的第二個accelerator_view物件。
__declspec(property(get= get_associated_accelerator_view)) Concurrency::accelerator_view associated_accelerator_view;
複製到
將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 存取類型。
__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);
傳回值
陣列原始數據的指標。
延伸區
取得範圍物件,該物件定義array的形狀。
__declspec(property(get= get_extent)) Concurrency::extent<_Rank> extent;
get_accelerator_view
傳回 accelerator_view 物件,代表 array 物件被配置的位置。 此屬性只能在 CPU 上存取。
Concurrency::accelerator_view get_accelerator_view() const;
傳回值
表示array物件配置位置的accelerator_view物件。
get_associated_accelerator_view(獲取相關加速器檢視)
取得呼叫過渡建構函式來實例化array物件時,做為參數傳遞的第二個accelerator_view物件。
Concurrency::accelerator_view get_associated_accelerator_view() const ;
傳回值
傳遞至暫存建構函式的第二個accelerator_view物件。
getCPUAccessType
傳回此陣列允許的CPU access_type。
access_type get_cpu_access_type() const restrict(cpu);
傳回值
get_extent
Concurrency::extent<_Rank> get_extent() const restrict(amp,cpu);
傳回值
extent的array物件。
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
本節來源最不重要的元件。
_我
元素的位置。
傳回值
參數所指定的元素值。
運算子[] (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);
參數
_指數
索引。
_我
索引。
傳回值
位於指定索引處的元素。
運算子=
複製指定 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 對象的參考。
順位
儲存array的排名。
static const int rank = _Rank;
重新解釋為
透過一維 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);
部分
傳回位於指定原點之 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
本節範圍中最不重要的元件。
_Ext
指定區段的範圍物件。 原點為 0。
_Idx
指定原點位置的索引物件。 子區段是範圍的其餘部分。
_I0
此部分的起源中最重要的組件。
_I1
本節來源的次重要元件。
_I2
本節來源最不重要的元件。
_排行
區段的排名。
_Section_extent
指定段落範圍的範圍物件。
_Section_origin
指定原點位置的索引物件。
value_type
複製之項目的數據類型。
傳回值
傳回位於指定原點之 array 物件的子區段,並選擇性地傳回具有指定範圍的 子區段。 當只指定index物件時,子區段會包含相關聯方格中的所有元素,其中這些元素的索引大於index物件中元素的索引。
檢視為
將這個陣列重新解譯為 不同順位的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物件。