std::slice
Материал из cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Заголовочный файл <valarray>
|
||
| class slice; |
||
std::slice является селектором класса, который определяет подмножество std::valarray похожи на BLAS срез. Объект типа std::slice содержит три значения: начальный индекс, шага, а общее количество значений в подмножеством. Объекты типа std::slice можно использовать в качестве индексов с operator[] valarray автора.Original:
std::slice is the selector class that identifies a subset of std::valarray similar to BLAS slice. An object of type std::slice holds three values: the starting index, the stride, and the total number of values in the subset. Objects of type std::slice can be used as indexes with valarray's operator[].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.
[править] Член функций
| создает срез Original: constructs a slice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (public функция-член) | |
| обращается начала среза Original: accesses the start of the slice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (public функция-член) | |
| доступ к размеру кусочек Original: accesses the size of the slice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (public функция-член) | |
| доступ шага среза Original: accesses the stride of the slice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (public функция-член) | |
[править] Пример
Платформы valarray поддерживаемого класса матрицы с проследить расчета функции .
Original:
Barebones valarray-backed Matrix class with a проследить calculating function.
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> class Matrix { std::valarray<int> data; int dim; public: Matrix(int r, int c) : data(r*c), dim(c) {} int& operator()(int r, int c) {return data[r*dim + c];} int trace() const { return data[std::slice(0, dim, dim+1)].sum(); } }; int main() { Matrix m(3,3); int n = 0; for(int r=0; r<3; ++r) for(int c=0; c<3; ++c) m(r, c) = ++n; std::cout << "Trace of the matrix (1,2,3) (4,5,6) (7,8,9) is " << m.trace() << '\n'; }
Вывод:
Trace of the matrix (1,2,3) (4,5,6) (7,8,9) is 15
[править] См. также
| получить / установить 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. (public функция-член) | |
| обобщенной кусочек valarray: начальный индекс, набор длин, набор шагов Original: generalized slice of a valarray: starting index, set of lengths, set of strides The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (класс) | |
| прокси подмножество valarray после применения срез Original: proxy to a subset of a valarray after applying a slice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон класса) | |