Domanda

I have multiple NxM matrices and want to select one of them by a variable. My best guess was to use boost::MultiArray to create a NxMxP matrix an then select via third dimension.

I implemented it using array_view:

typedef boost::multi_array<double, 3> threeDimMatrix;
typedef threeDimMatrix::index_range rangeDim;
threeDimMatrix hypotheses(boost::extents[nInputs][nStates][nChan]);
threeDimMatrix::array_view<2>::type hypothesesAdd =
     hypotheses[boost::indices[rangeDim(0,2)][rangeDim(0,2)][ IDX ] ];

Unfortunately I then want to continue my code with this matrix as a boost::matrix and don't know how to. Can I do something like a cast?

Or is it even possible without multi_array? Can I else somehow select a matrix via variable?

È stato utile?

Soluzione

Instead of having a 3 dimensional array, can't you just keep your Boost matrices as they are and have a mapper to them? Then no casts are necessary and you should not have any problems.

The mapper could be a basic array where the index will be your key, or use the C++ library cplusplus.com/reference/stl/map.

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