Wednesday, 15 January 2014

c++ - In armadillo, how to interpret result of find on submatrix -


In the specified rows and columns of the matrix, find the following code using Armadillo to find the first 7 (by finding the first columns) Do:

  using namespace arma; Euvecy 2 First Evil 7 (Cost Matt and X, Constant UVC and Rouse, Construct Euvel and Coles) {Const Yeward Search Quint = 1; UVC results = search (X. subsystem (rows, columns) == 7, search code); If (results.empty ()) std :: logic_error ("7 not found!"); Ind returns (X, results [0]); }  

There are two problems with this first, giving us a single vectorised indicator for each result, so to convert it to a line and column, let us call MATLAB's ind2sub Calling functions like , but surprisingly does not exist in Armadillo. Okay, this is a pain, but I can write myself in two rows (but I mention that there is a better way for someone to do this.)

A big problem That is the result of an submatrix example if X is 100x100 but line = cols = {98,99} then the bottom right hand corner < Code> find (...) == 3 instead of find (...) == 9999 . How do I achieve absolute results?

An alternative is to:

  using namespace ARA; Euvecy 2 First Evil 7 (Cost Matt and X, Constant UVC and Rouse, Construct Euvel and Coles) {Const Yeward Search Quint = 1; Auto submatOfX = X.submat (rows, columns); // Do not do it! Uveysecimal = search (submatOfX == 7, findCount); If (results.empty ()) std :: logic_error ("7 not found!"); Uveceee 2 submitted index = ind 2 sub (submount, result [0]); Return uvec2 {rows [sub indiards [0]], cols [submatIndices [1]]}; } I think that they will run (assuming that we have implemented  ind2sub , but it is wildly incompetent. The problem contains the fact that  SubmatOfX  is not really a matrix, but there is a small proxy type so that Armadillo does not need to copy all the submatrix elements into a new matrix, just do the operation to find it. But it does  ind2sub By passing on  it is converted to a  mat . The matrix copy is done after all! 

Pushing with this possible solution, I can create templates on

ind2sub on the type of matrix type so that the proxy directly It will probably work, but rather than a complex solution that was originally hoped, there will be a very few functions. What's more, proxy type in Armadillo is not really documented and I do not think that using They are about to mess with them, so I'm worried that for a while even in a single variable, it is a little fragile. Does anyone have any better ideas?

In the absence of any answer, I think the conclusion should be that Ardadillo's MATLAB-like syntax Just not powerful enough for this kind of work. It is a good thing for small things to fit in one line, but if it is more complex then we have to be forced to recapture ourselves. Certainly the following code Regardless of the time, the first code As Nipet less than clear.

  using namespace ARA; // Note: Rows and columns are now logical vectors (i.e. {1 ... 0}}, // instead of indexed vectors (i.e. {0, 2, 3, ...}) UVC2 is the first Awwal 7 (Constant Mate and X, Construct UVC & Rouses, Construct UVC and Coles) (for uveenu c = 0; c & lt; x.n_cols; ++ c) {continue (! Cols (c)); For (YewR R = 0; R. lt; X.n_rows; ++ r) (if (rows (r) continue); if (x (r, c) == 7) {returns uvec 2 {r} , C}}}}} Std :: logic_error throw ("7 is not found!")}  

Note that the external loop column is important and should be one of the internal rows The matrix is ​​stored by column-wise armbilo, so this type of speed is progressed rather than progress through memory, thereby making things happen Mr. momentum is growing because we could get more cash hit.


No comments:

Post a Comment