I have searched the web but could not find an answer. how do I have set base index in the matrix, such that indexes start from values other than zero? for example:
A(-3:1) // Matlab/fortran equivalent
A.reindex(-3); // boost multi-array eq开发者_如何学Gouivalent
thanks
Your search appears to be correct; it appears not to have such a function.
If you really need this functionality, perhaps you could consider subclassing the matrix and overriding the operator() to fiddle with the indices for you. For example:
using namespace boost::numeric::ublas;
template<typename T>
class Reindexable : public matrix<T>
{
public:
Reindexable() : m_offset(0) {}
void reindex(int offset) { m_offset = offset; }
T& operator()(int i) { return matrix<T>::operator()(i + m_offset); }
/* Probably more implementation needed here ... */
private:
int m_offset;
}
I've been programming in VB.NET (ughh!) and C# lately, so I'm a little rusty on my C++ syntax and have probably made a few mistakes in the above, but the general idea should work. You subclass the matrix so that you can provide a reindex operation and override the parenthesis operator so that it is aware of the new index offset. Of course, in the actual implementation, you will need offsets for each dimension of the matrix.
Also, if you ever have a reference or pointer to your Reindexable
, and the type of the reference/pointer is matrix<T>
, then you will be using the old index operator, so be careful!
精彩评论