Domanda

Ho un grande multi_array 2D che ho bisogno di ridurre a un insieme ridotto di dati (anche 2D). In fase di esecuzione Ho un vettore di indici di colonna che si desidera selezionare e mettere in sub-array.

Lo so che è possibile creare un sub-array dalla matrice originale utilizzando boost :: :: multi_array_types index_range, ma tutti gli esempi che sto vedendo uso hardcoded gamme. C'è un modo per impostare l'index_range in fase di esecuzione utilizzando un vettore di valori, o è solo non è possibile in multi_array?

sto cercando di fare qualcosa di simile

vector<int> columnIndex; // contains some values
boost::multi_array_types::index_range range;
for(int idx = 0; idx < columnIndex.size(); ++idx)
     range = columnIndex[idx];
È stato utile?

Soluzione

I looked into the boost code for boost::multi_array_types::index_range, and found that this is not possible. The class has only three members to store index values - start, finish, and stride. It can't store a more complex set of values.

Since the number of columns that I need is dynamic, I used a vector of sub-arrays (array_view),

vector<boost::multi_array_ref<double, 2>::array_view<2>::type::const_reference

and just added to the vector as needed.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top