◐ Shell
clean mode source ↗

std::gslice - cppreference.com

Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate.

La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí.

Definido en el archivo de encabezado <valarray>

class gslice;

std::gslice es el selector de clase que identifica un subconjunto de los índices de std::valarray definidas por un conjunto de múltiples niveles de avances y tamaños. Objetos de std::gslice tipo se puede utilizar como índices con operator[] valarray para seleccionar, por ejemplo, las columnas de una matriz multidimensional representado como un 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.

Dada la s valor inicial, una lista de los pasos i
j
y una lista de tamaños d
j
, un std::gslice construido a partir de estos valores se selecciona el conjunto de índices k
j
=s+Σ
j
(i
j
d
j
)
.

Original:

Given the starting value s, a list of strides i
j
and a list of sizes d
j
, a std::gslice constructed from these values selects the set of indices k
j
=s+Σ
j
(i
j
d
j
)
.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Por ejemplo, un GSlice con 3 índice de inicio, pasos {19,4,1} y longitudes {2,4,3} genera el siguiente conjunto de índices:

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.

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

Es posible construir objetos std::gslice que seleccionan algunos de los índices más de una vez: si el ejemplo anterior utiliza el {1,1,1} pasos, los índices habría sido {3, 4, 5, 4, 5, 6, ...} . Gslices Solamente pueden utilizarse como argumentos a la versión const std::valarray::operator[] de lo contrario, el comportamiento no está definido .

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.

Las funciones miembro

construye una 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.


(función miembro pública)

accede al inicio de la 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.


(función miembro pública)

accede a la gran variedad de pasos de la 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.


(función miembro pública)

accede a la matriz de sizees de la GSlice

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.


(función miembro pública)

Ejemplo

muestra el uso de gslices para hacer frente a las columnas de una matriz 3D

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.

#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);
}

Salida:

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

Ver también

obtener / establecer un elemento de valarray, sector o máscara
(función miembro pública) [editar]

BLAS-como una rebanada de valarray: índice de inicio, duración, ritmo

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.


(clase) [editar]

proxy para un subconjunto de un valarray después de aplicar un GSlice

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.


(plantilla de clase) [editar]