std::gslice
提供: cppreference.com
![]() | このページは、Google 翻訳を使って英語版から機械翻訳されました。 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
Defined in header <valarray> | ||
class gslice; | ||
std::gslice
進歩やサイズのマルチレベル·セットで定義されているstd::valarrayインデックスのサブセットを識別するセレクタクラスです。タイプstd::gslice
のオブジェクトを選択するvalarrayのoperator[]
と指標として使用することができ、例えば、多次元配列の列はvalarray
として表さ.Original:
std::gslice
is the selector class that identifies a subset of std::valarray indices defined by a multi-level set of strides and sizes. Objects of type std::gslice
can be used as indices with valarray's operator[]
to select, for example, columns of a multidimensional array represented as a valarray
.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
開始値のs、ストライドのリストi
jとサイズのリストd
j考えると、これらの値から構成さ
j=s+Σ
j(i
jd
j)のセットを選択.
jとサイズのリストd
j考えると、これらの値から構成さ
std::gslice
は、インデックスkj=s+Σ
j(i
jd
j)のセットを選択.
Original:
Given the starting value s, a list of strides i
j and a list of sizes d
j, a
j=s+Σ
j(i
jd
j).
j and a list of sizes d
j, a
std::gslice
constructed from these values selects the set of indices kj=s+Σ
j(i
jd
j).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
たとえば、開始インデックス
3
、ストライド{19,4,1
}と長さを持つgslice{2,4,3}
は、インデックスの次のセットを生成しますOriginal:
For example, a gslice with starting index
3
, strides {19,4,1
} and lengths {2,4,3}
generates the following set of indices:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
3+0*19+0*4+0*1=3,
3+0*19+0*4+1*1=4,
3+0*19+0*4+2*1=5,
3+0*19+1*4+0*1=7,
3+0*19+1*4+1*1=8,
...
3+1*19+3*4+2*1=36
これは、複数回、いくつかの指標を選択
std::gslice
オブジェクトを構築することが可能である:上記の例では、進歩の{1,1,1}
を使用した場合、インデックスは{3, 4, 5, 4, 5, 6, ...}
されていると思います。このようなgslicesだけstd::valarray::operator[]
のconstバージョンへの引数として使用することができ、そうでない場合の動作は未定義です.Original:
It is possible to construct
std::gslice
objects that select some indices more than once: if the above example used the strides {1,1,1}
, the indices would have been {3, 4, 5, 4, 5, 6, ...}
. Such gslices may only be used as arguments to the const version of std::valarray::operator[]
, otherwise the behavior is undefined.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集]メンバ関数
gsliceを構築します Original: constructs a gslice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
gsliceの開始をアクセスします Original: accesses the start of the gslice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
gsliceの進歩の配列にアクセスします Original: accesses the array of strides of the gslice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
gsliceのsizeesの配列にアクセスします Original: accesses the array of sizees of the gslice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) |
[編集]例
3次元配列の列に対処するためのgslicesの使用方法を示します
Original:
demonstrates the use of gslices to address columns of a 3D array
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
このコードを実行します
#include <iostream>#include <valarray>void test_print(std::valarray<int>& v, int rows, int cols, int planes){for(int r=0; r<rows;++r){for(int c=0; c<cols;++c){for(int z=0; z<planes;++z)std::cout<< v[r*cols*planes + c*planes + z]<<' ';std::cout<<'\n';}std::cout<<'\n';}}int main(){std::valarray<int> v =// 3d array: 2 x 4 x 3 elements{111,112,113 , 121,122,123 , 131,132,133 , 141,142,143, 211,212,213 , 221,222,223 , 231,232,233 , 241,242,243};// int ar3d[2][4][3]std::cout<<"Initial 2x4x3 array:\n"; test_print(v, 2, 4, 3); // update every value in the first columns of both planes v[std::gslice(0, {2, 4}, {4*3, 3})]=1;// two level one strides of 12 elements// then four level two strides of 3 elements // subtract the third column from the second column in the 1st plane v[std::gslice(1, {1, 4}, {4*3, 3})]-= v[std::gslice(2, {1, 4}, {4*3, 3})]; std::cout<<"After column operations: \n"; test_print(v, 2, 4, 3);}
出力:
Initial 2x4x3 array: 111 112 113 121 122 123 131 132 133 141 142 143 211 212 213 221 222 223 231 232 233 241 242 243 After column operations: 1 -1 113 1 -1 123 1 -1 133 1 -1 143 1 212 213 1 222 223 1 232 233 1 242 243
[編集]参照
valarrayの要素、スライス、またはマスクを設定/取得する Original: get/set valarray element, slice, or mask The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
BLASのようなvalarrayのスライス:開始インデックス、長さ、ストライド Original: BLAS-like slice of a valarray: starting index, length, stride The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (クラス) | |
gsliceを適用した後のvalarrayのサブセットへのプロキシ Original: proxy to a subset of a valarray after applying a gslice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (クラステンプレート) |